| Routines

13999: THE 'INT' FUNCTION (offset 39)

The address of this routine is found in the table of addresses. It is called via the calculator literal 39 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 | 13999 | RST 40 | X
| 14000 | DEFB 49 | duplicate: X, X
| 14001 | DEFB 54 | less_0: X, (1/0)
| 14002 | DEFB 0 | jump_true to X_NEG: X
| 14003 | DEFB 4
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.
| 14004 | DEFB 58 | truncate: I(X)
| 14005 | DEFB 56 | end_calc
| 14006 | RET | Finished.
When X is a negative integer I(X) is returned, otherwise I(X)-1 is returned.
X_NEG | 14007 | DEFB 49 | duplicate: X, X
| 14008 | DEFB 58 | truncate: X, I(X)
| 14009 | DEFB 192 | st_mem_0: X, I(X) (mem-0 holds I(X))
| 14010 | DEFB 3 | subtract: X-I(X)
| 14011 | DEFB 224 | get_mem_0: X-I(X), I(X)
| 14012 | DEFB 1 | exchange: I(X), X-I(X)
| 14013 | DEFB 48 | f_not: I(X), (1/0)
| 14014 | DEFB 0 | jump_true to EXIT: I(X)
| 14015 | DEFB 3
The jump is made for values of X that are negative integers, otherwise there is no jump and I(X)-1 is calculated.
| 14016 | DEFB 161 | stk_one: I(X), 1
| 14017 | DEFB 3 | subtract: I(X)-1
In either case the subroutine finishes with:
EXIT | 14018 | DEFB 56 | end_calc: I(X) or I(X)-1
| 14019 | RET |