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

dunbarx at aol.com dunbarx at aol.com
Thu Dec 10 14:13:44 EST 2015


Here is the link:


http://forums.livecode.com/viewtopic.php?f=7&t=25132&hilit=routines+for+very


Craig



-----Original Message-----
From: Peter TB Brett <peter.brett at livecode.com>
To: How to use LiveCode <use-livecode at lists.runrev.com>
Sent: Thu, Dec 10, 2015 1:47 pm
Subject: Re: Why aren't large numbers limited to 64 bit values?

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