Prev: 14020 Up: Map Next: 14211
14099: THE 'NATURAL LOGARITHM' FUNCTION (offset 37)
The address of this routine is found in the table of addresses. It is called via the calculator literal 37 by the routine at to_power. It is also called indirectly via fp_calc_2.
This subroutine handles the function LN X and is the second of the four routines that use the series generator to produce Chebyshev polynomials.
The approximation to LN X is found as follows:
  • i. X is tested and report A is given if X is not positive.
  • ii. X is then split into its true exponent, e', and its mantissa X'=X/(2**e'), where 0.5<=X'<1.
  • iii. The required value Y1 or Y2 is formed: if X'>0.8 then Y1=e'*LN 2, otherwise Y2=(e'-1)*LN 2.
  • iv. If X'>0.8 then the quantity X'-1 is stacked; otherwise 2*X'-1 is stacked.
  • v. Now the argument Z is formed, being 2.5*X'-3 if X'>0.8, otherwise 5*X'-3. In each case, -1<=Z<=1, as required for the series to converge.
  • vi. The series generator is used to produce the required function.
  • vii. Finally a simple multiplication and addition leads to LN X being returned as the 'last value'.
Input
Output
ln 14099 RST 40 X
Perform step i.
14100 DEFB 61 re_stack: X (in full floating-point form)
14101 DEFB 49 duplicate: X, X
14102 DEFB 55 greater_0: X, (1/0)
14103 DEFB 0 jump_true to VALID: X
14104 DEFB 4 multiply: X
14105 DEFB 56 end_calc: X
Report A - Invalid argument.
14106 RST 8 Call the error handling routine.
14107 DEFB 9
Perform step ii.
VALID 14108 DEFB 160 stk_zero: X, 0 (the deleted 1 is overwritten with zero)
14109 DEFB 2 delete: X
14110 DEFB 56 end_calc: X
14111 LD A,(HL) The exponent, e, goes into A.
14112 LD (HL),128 X is reduced to X'.
14114 CALL STACK_A The stack holds: X', e.
14117 RST 40 X', e
14118 DEFB 52 stk_data: X', e, 128
14119 DEFB 56,0
14121 DEFB 3 subtract: X', e'
Perform step iii.
14122 DEFB 1 exchange: e', X'
14123 DEFB 49 duplicate: e', X', X'
14124 DEFB 52 stk_data: e', X', X', 0.8
14125 DEFB 240,76,204,204,205
14130 DEFB 3 subtract: e', X', X'-0.8
14131 DEFB 55 greater_0: e', X', (1/0)
14132 DEFB 0 jump_true to GRE_8: e', X'
14133 DEFB 8
14134 DEFB 1 exchange: X', e'
14135 DEFB 161 stk_one: X', e', 1
14136 DEFB 3 subtract: X', e'-1
14137 DEFB 1 exchange: e'-1, X'
14138 DEFB 56 end_calc
14139 INC (HL) Double X' to give 2*X'.
14140 RST 40 e'-1, 2*X'
GRE_8 14141 DEFB 1 exchange: X', e' (X'>0.8) or 2*X', e'-1 (X'<=0.8)
14142 DEFB 52 stk_data: X', e', LN 2 or 2*X', e'-1, LN 2
14143 DEFB 240,49,114,23,248
14148 DEFB 4 multiply: X', e'*LN 2=Y1 or 2*X', (e'-1)*LN 2=Y2
Perform step iv.
14149 DEFB 1 exchange: Y1, X' (X'>0.8) or Y2, 2*X' (X'<=0.8)
14150 DEFB 162 stk_half: Y1, X', .5 or Y2, 2*X', .5
14151 DEFB 3 subtract: Y1, X'-.5 or Y2, 2*X'-.5
14152 DEFB 162 stk_half: Y1, X'-.5, .5 or Y2, 2*X'-.5, .5
14153 DEFB 3 subtract: Y1, X'-1 or Y2, 2*X'-1
Perform step v.
14154 DEFB 49 duplicate: Y, X'-1, X'-1 or Y2, 2*X'-1, 2*X'-1
14155 DEFB 52 stk_data: Y1, X'-1, X'-1, 2.5 or Y2, 2*X'-1, 2*X'-1, 2.5
14156 DEFB 50,32
14158 DEFB 4 multiply: Y1, X'-1, 2.5*X'-2.5 or Y2, 2*X'-1, 5*X'-2.5
14159 DEFB 162 stk_half: Y1, X'-1, 2.5*X'-2.5, .5 or Y2, 2*X'-1, 5*X'-2.5, .5
14160 DEFB 3 subtract: Y1, X'-1, 2.5*X'-3=Z or Y2, 2*X'-1, 5*X'-3=Z
Perform step vi, passing to the series generator the parameter '12', and the twelve constants required.
14161 DEFB 140 series_0C: Y1, X'-1, Z or Y2, 2*X'-1, Z
14162 DEFB 17,172
14164 DEFB 20,9
14166 DEFB 86,218,165
14169 DEFB 89,48,197
14172 DEFB 92,144,170
14175 DEFB 158,112,111,97
14179 DEFB 161,203,218,150
14183 DEFB 164,49,159,180
14187 DEFB 231,160,254,92,252
14192 DEFB 234,27,67,202,54
14197 DEFB 237,167,156,126,94
14202 DEFB 240,110,35,128,147
At the end of the last loop the 'last value' is:
  • LN X'/(X'-1) if X'>0.8
  • LN (2*X')/(2*X'-1) if X'<=0.8
Perform step vii.
14207 DEFB 4 multiply: Y1=LN (2**e'), LN X' or Y2=LN (2**(e'-1)), LN (2*X')
14208 DEFB 15 addition: LN (2**e')*X')=LN X or LN (2**(e'-1)*2*X')=LN X
14209 DEFB 56 end_calc: LN X
14210 RET Finished: 'last value' is LN X.
Prev: 14020 Up: Map Next: 14211