manual:chapter3:numformat

A number can have a base-10 exponent up to 30,000 (note that the stock 50g ROM only allows an exponent up to 499). Thus, numbers can range from $10^{-30,000}$ to $10^{+30,000}$.

The precision is a user selectable parameter, using SETPREC. The default is 32 digits of precision. The maximum is 2000 digits of precision (for comparison, the stock 50g ROM has a fixed precision of 12 digits displayed, 15 digits internally). While the current precision is a system-wide setting, each number retains the precision it used when it was calculated, even if the user reduces the precision setting, a number on the stack will retain its digits. An interesting aspect of this precision implementation is that it can be changed mid-stream through a calculation if more digits are needed and then changed back, without affecting the rest of the chain of calculation (should certain critical parts of the calculation require higher precision).

Of course, the more precision a number has, the larger the amount of memory required to store it. The system will try to optimize and store the least possible number of digits without altering the number. For example calculating 1 2 / will result in the number 0.5 which only needs to store one single digit regardless of the system-wide precision setting. On the other hand, calculating 1 3 / at 2000 digits precision will need to store 2000 digits.

There's one more optimization the system will attempt: when a number is an integer it will be stored as a “compact” number rather than as a variable precision real number. This is all transparent to the user, the user need not be concerned with the storage format at all except when trying to compute the required storage space. The system will operate on numbers properly regardless of the storage format. Storage is not the only gains from using a compact format for small integers, but operating on these integers is much faster when they stay within the range of the compact storage, helping speed up loops (where integers are typically used as counters).

The storage requirements for numbers are as follows:

 Number Type Number Range Bytes of storage including a 4-byte object prolog Small integer -130,000 to +130,000 4 (number is bit-encoded within the prolog) 64-bit integer $-2^{63}$ to $2^{63}$ (but outside previous range) 12 (a prolog + a 64-bit number) Larger integers or reals any 8+4*(N/8), where N=smallest multiple of 8 > precision number of digits Complex any Sum of space for real and imaginary parts plus 4 bytes

At the default precision of 32 digits, a real number would require a maximum of 24 bytes. This is 4 bytes for the prolog, 4 bytes for the sign, exponent and other flags, and 4 bytes for every 8 digits stored.

• manual/chapter3/numformat.txt