Integer or not integer?
A calculation result can be meant to be integer, can look like an integer, and still, due to the internal workings of the computer, may not be an integer. To illustrate this, let's draw the cubic root of 3 (the question mark is Hypatia's input prompt, you do not type it):
? 27 CBRT
= 3
So far, so good, but
? ISPOSINT
= 0
It is not an integer! What is it, then? Let's find out, by subtracting 3:
? 27 CBRT 3 -
= -2.16840434497101e-19
The deviation from 3 is in the 19th digit after the decimal point. For most practical purposes this is negligible, but obviously the result should be 3, not 2.9999999999999999998...
To deal with this issue, Hypatia employs a mechanism that it idiosyncratically calls "integer bias": a bias towards integer results. When a result is very close to an integer (deviating only after the 17th digit), then Hypatia assumes it should be an integer, and makes it an integer.
This mechanism is enabled by default. In fact, when you try the above example without having integer bias disabled, you actually get the result you'd expect:
? 27 CBRT 3 -
= 0
The commands INTEGER ON and INTEGER OFF enable/disable Hypatia's integer bias. INTEGER ON is default, INTEGER alone shows the current status. For the original example, integer bias was disabled.
The integer bias is not applied to the end result of a calculation line, but immediately to each operator's results. Therefore, with integer bias ON (as by default), you can calculate the factorial of the cubic root of 27, while with integer bias OFF, you get an error message:
? 27 CBRT !
= 6
? INTEGER OFF
? 27 CBRT !
Error: factorial of non-integer number
Unless you have a specific reason to disable integer bias, it is best to leave it ON.
Note that "deviating after the 17th digit" refers to the 17th significant digit, not to the 17th digit after the decimal point.
Integer bias is only applied to numbers less than 10e15 (max. 15 digits before the decimal point).
The zero threshold deals with an entirely different issue, integer bias is not applied to results close to zero!
Home, Up: Numbers, Prev: The Zero Threshold, Next Chapter: Variables and User-Defined Constants