Why aren't large numbers limited to 64 bit values?

Peter TB Brett peter.brett at livecode.com
Thu Dec 10 13:46:22 EST 2015


On 2015-12-10 17:54, Geoff Canyon wrote:
> LiveCode works in 64 bit numbers, so why does
> 
> put 10000000000 * 1000000000000000000000000000000
> 
> result in
> 
> 10000000000000000303786028427003666890752
> 
> which is close to the right answer, instead of some 18 digit value?

When numbers are too large to represent exactly, LiveCode automatically 
shifts to using 64-bit IEEE floating point representation.  
Floating-point numbers store a number in three pieces:

1) a sign bit
2) an exponent (11 bits)
3) a mantissa (52 bits)

This is a bit like writing decimal scientific notation.  The "true" 
value is 1.<MANTISSA> * 2^<EXPONENT>, modified by the SIGN.

This means that much much larger numbers than 2^64 can be represented in 
only 64 bits, but at the cost of loss of accuracy (because the mantissa 
is only 53 bits).  As you've noticed, the result of your calculation is 
only *close to* the right answer.  It can accurately represent any 
number that only requires 53 bits of precision.

See also 
https://en.wikipedia.org/wiki/Double-precision_floating-point_format

                                           Peter

-- 
Dr Peter Brett <peter.brett at livecode.com>
LiveCode Open Source Team

LiveCode on reddit! <https://reddit.com/r/livecode>




More information about the use-livecode mailing list