Prev: 13999 Up: Map Next: 14099
14020: THE 'EXPONENTIAL' FUNCTION (offset 38)
Used by the routine at to_power.
The address of this routine is found in the table of addresses. It is called indirectly via fp_calc_2.
This subroutine handles the function EXP X and is the first of four routines that use the series generator to produce Chebyshev polynomials.
The approximation to EXP X is found as follows:
  • i. X is divided by LN 2 to give Y, so that 2**Y is now the required result.
  • ii. The value N is found, such that N=INT Y.
  • iii. The value W=Y-N is found; 0<=W<=1, as required for the series to converge.
  • iv. The argument Z=2*W-1 is formed.
  • v. The series generator is used to return 2**W.
  • vi. Finally N is added to the exponent, giving 2**(N+W), which is 2**Y and therefore the required answer.
exp 14020 RST 40 X
Perform step i.
14021 DEFB 61 re_stack: X (in full floating-point form)
14022 DEFB 52 stk_data: X, 1/LN 2
14023 DEFB 241,56,170,59,41
14028 DEFB 4 multiply: X/LN 2=Y
Perform step ii.
14029 DEFB 49 duplicate: Y, Y
14030 DEFB 39 int: Y, INT Y=N
14031 DEFB 195 st_mem_3: Y, N (mem-3 holds N)
Perform step iii.
14032 DEFB 3 subtract: Y-N=W
Perform step iv.
14033 DEFB 49 duplicate: W, W
14034 DEFB 15 addition: 2*W
14035 DEFB 161 stk_one: 2*W, 1
14036 DEFB 3 subtract: 2*W-1=Z
Perform step v, passing to the series generator the parameter '8' and the eight constants required.
14037 DEFB 136 series_08: Z
14038 DEFB 19,54
14040 DEFB 88,101,102
14043 DEFB 157,120,101,64
14047 DEFB 162,96,50,201
14051 DEFB 231,33,247,175,36
14056 DEFB 235,47,176,176,20
14061 DEFB 238,126,187,148,88
14066 DEFB 241,58,126,248,207
At the end of the last loop the 'last value' is 2**W.
Perform step vi.
14071 DEFB 227 get_mem_3: 2**W, N
14072 DEFB 56 end_calc
14073 CALL FP_TO_A The absolute value of N mod 256 is put into the A register.
14076 JR NZ,N_NEGTV Jump forward if N was negative.
14078 JR C,REPORT_6_2 Error if ABS N>255.
14080 ADD A,(HL) Now add ABS N to the exponent.
14081 JR NC,RESULT_OK Jump unless e>255.
Report 6 - Number too big.
REPORT_6_2 14083 RST 8 Call the error handling routine.
14084 DEFB 5
N_NEGTV 14085 JR C,RSLT_ZERO The result is to be zero if N<-255.
14087 SUB (HL) Subtract ABS N from the exponent as N was negative.
14088 JR NC,RSLT_ZERO Zero result if e less than zero.
14090 NEG Minus e is changed to e.
RESULT_OK 14092 LD (HL),A The exponent, e, is entered.
14093 RET Finished: 'last value' is EXP X.
RSLT_ZERO 14094 RST 40 Use the calculator to make the 'last value' zero.
14095 DEFB 2 delete (the stack is now empty)
14096 DEFB 160 stk_zero: 0
14097 DEFB 56 end_calc
14098 RET Finished, with EXP X=0.
Prev: 13999 Up: Map Next: 14099