couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Adam Kocoloski <>
Subject Re: Silent corruption of large numbers
Date Wed, 11 Nov 2009 00:52:25 GMT
On Nov 10, 2009, at 7:46 PM, Noah Slater wrote:

> On 11 Nov 2009, at 00:23, Roger Binns wrote:
>> As a developer past practise has trained me that integers are exact  
>> and
>> floating point is approximate (also "fast" and "slow"  
>> respectively).  Other
>> than some older BASICs, Javascript is the first time in ages to  
>> come across
>> a language that doesn't have integers, and representing everything  
>> as float.
>> I looked up a few Javascript tutorials and didn't find a single one  
>> stating
>> that all numbers are stored as float.  In most cases they  
>> deliberately
>> distinguish between integers and floating point as two different  
>> types.
>> Integers can have leading 0x/0 to specify hex/octal whereas  
>> floating point
>> cannot is why they seem to make the distinction.
> What difference does it make? An integer will never be "corrupted"  
> into anything other than the original value. The only real problem  
> is when trying to deal with decimals, as they will be "corrupted" to  
> the nearest representable value in floating point. Right? What am I  
> missing.

Hi Noah, I think the part you're missing is that JavaScript does not  
actually have integers.  All numbers are internally represented using  
double-precision floating point.  So in fact a number that looks like  
an integer can be corrupted.  Easiest way to see this, as Roger  
pointed out, is to try to enter something like


as the value for a field in Futon.  You can't do it, Futon will  
corrupt it and give you back


Best, Adam

View raw message