| Routines

36AF: THE 'INT' FUNCTION (offset +27)

The address of this routine is found in the table of addresses. It is called via the calculator literal +27 by the routines at BEEP, FP_TO_BC, LOG_2_A, PRINT_FP, n_mod_m, exp and get_argt. It is also called indirectly via fp_calc_2. This subroutine handles the function INT X and returns a 'last value' that is the 'integer part' of the value supplied. Thus INT 2.4 gives 2 but as the subroutine always rounds the result down INT -2.4 gives -3. The subroutine uses truncate to produce I(X) such that I(2.4)=2 and I(-2.4)=-2. Thus, INT X is given by I(X) when X>=0, and by I(X)-1 for negative values of X that are not already integers, when the result is, of course, I(X).
int | 36AF | RST $28 | X
| 36B0 | DEFB $31 | duplicate: X, X
| 36B1 | DEFB $36 | less_0: X, (1/0)
| 36B2 | DEFB $00 | jump_true to X_NEG: X
| 36B3 | DEFB $04
For values of X that have been shown to be greater than or equal to zero there is no jump and I(X) is readily found.
| 36B4 | DEFB $3A | truncate: I(X)
| 36B5 | DEFB $38 | end_calc
| 36B6 | RET | Finished.
When X is a negative integer I(X) is returned, otherwise I(X)-1 is returned.
X_NEG | 36B7 | DEFB $31 | duplicate: X, X
| 36B8 | DEFB $3A | truncate: X, I(X)
| 36B9 | DEFB $C0 | st_mem_0: X, I(X) (mem-0 holds I(X))
| 36BA | DEFB $03 | subtract: X-I(X)
| 36BB | DEFB $E0 | get_mem_0: X-I(X), I(X)
| 36BC | DEFB $01 | exchange: I(X), X-I(X)
| 36BD | DEFB $30 | f_not: I(X), (1/0)
| 36BE | DEFB $00 | jump_true to EXIT: I(X)
| 36BF | DEFB $03
The jump is made for values of X that are negative integers, otherwise there is no jump and I(X)-1 is calculated.
| 36C0 | DEFB $A1 | stk_one: I(X), 1
| 36C1 | DEFB $03 | subtract: I(X)-1
In either case the subroutine finishes with:
EXIT | 36C2 | DEFB $38 | end_calc: I(X) or I(X)-1
| 36C3 | RET |