Why aren't large numbers limited to 64 bit values?
Bob Sneidar
bobsneidar at iotecdigital.com
Thu Dec 10 14:05:26 EST 2015
Looks like the largest decimal number that can be represented then is 4.50359962737E+15, or 4503599627370000
Bob S
> On Dec 10, 2015, at 10:46 , Peter TB Brett <peter.brett at livecode.com> wrote:
>
> 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>
>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
More information about the use-livecode
mailing list