| Routines

3851: THE 'EXPONENTIATION' OPERATION (offset +06)

The address of this routine is found in the table of addresses. It is called indirectly via fp_calc_2, and the routine at sqr continues here. This subroutine performs the binary operation of raising the first number, X, to the power of the second number, Y. The subroutine treats the result X**Y as being equivalent to EXP (Y*LN X). It returns this value unless X is zero, in which case it returns 1 if Y is also zero (0**0=1), returns zero if Y is positive, and reports arithmetic overflow if Y is negative.
to_power | 3851 | RST $28 | X, Y
| 3852 | DEFB $01 | exchange: Y, X
| 3853 | DEFB $31 | duplicate: Y, X, X
| 3854 | DEFB $30 | f_not: Y, X, (1/0)
| 3855 | DEFB $00 | jump_true to XIS0: Y, X
| 3856 | DEFB $07
The jump is made if X=0, otherwise EXP (Y*LN X) is formed.
| 3857 | DEFB $25 | ln: Y, LN X
Giving report A if X is negative.
| 3858 | DEFB $04 | multiply: Y*LN X
| 3859 | DEFB $38 | end_calc
| 385A | JP exp | Exit via exp to form EXP (Y*LN X).
The value of X is zero so consider the three possible cases involved.
XIS0 | 385D | DEFB $02 | delete: Y
| 385E | DEFB $31 | duplicate: Y, Y
| 385F | DEFB $30 | f_not: Y, (1/0)
| 3860 | DEFB $00 | jump_true to ONE: Y
| 3861 | DEFB $09
The jump is made if X=0 and Y=0, otherwise proceed.
| 3862 | DEFB $A0 | stk_zero: Y, 0
| 3863 | DEFB $01 | exchange: 0, Y
| 3864 | DEFB $37 | greater_0: 0, (1/0)
| 3865 | DEFB $00 | jump_true to LAST: 0
| 3866 | DEFB $06
The jump is made if X=0 and Y is positive, otherwise proceed.
| 3867 | DEFB $A1 | stk_one: 0, 1
| 3868 | DEFB $01 | exchange: 1, 0
| 3869 | DEFB $05 | division: Exit via division as dividing by zero gives 'arithmetic overflow'.
The result is to be 1 for the operation.
ONE | 386A | DEFB $02 | delete: -
| 386B | DEFB $A1 | stk_one: 1
Now return with the 'last value' on the stack being 0**Y.
LAST | 386C | DEFB $38 | end_calc: (1/0)
| 386D | RET | Finished: 'last value' is 0 or 1.