manual:chapter3:numformat

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
manual:chapter3:numformat [2017/06/11 17:43]
smartin
manual:chapter3:numformat [2022/03/08 13:20] (current)
claudio
Line 1: Line 1:
 ===== Number ranges, precision, and storage sizes ===== ===== Number ranges, precision, and storage sizes =====
  
-An approximate number can have an 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}$.+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 for approximate numbers 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).  One nice aspect of this precision implementation is that it can be changed mid-stream through a calculation then changed back, without affecting the rest of the chain of calculation (should certain critical parts of the calculation require higher precision).+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 amount of memory is required to store it.  Here are the storage requirements for numbers:+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.
  
-| **Number Type** | **Number Range** | **Bytes of storage** | +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 userthe 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 storagehelping speed up loops (where integers are typically used as counters).
-|Exact|-130,000 to +130,000|4| +
-|Exact|$-2^{63}$ to $2^{63}$ (but outside previous range)|12| +
-|Approximate|any|8+4*(N/8), where N=smallest multiple of 8 > precision number of digits|+
  
-At the default precision of 32 digits, an approximate number would require a maximum of 24 bytes.+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.1497228204.txt.gz
  • Last modified: 2017/06/11 17:43
  • by smartin