When is 632769996261406250 632769996261406200?

M

Mike Ratcliffe

I realize that numeric accuracy is not perfect in JS but from what I
have read in the FAQ etc. it seems that the number 632769996261406250
should be easily handled by JavaScript.

The following:
alert(632769996261406250)

Displays 632769996261406200 ... does anybody know why?
 
R

Richard Cornford

I realize that numeric accuracy is not perfect in JS but from what I
have read in the FAQ etc. it seems that the number 632769996261406250
should be easily handled by JavaScript.

The following:
alert(632769996261406250)

Displays 632769996261406200 ... does anybody know why?

With IEEE double precision floating point numbers the range of
precisely representable positive integers goes up to 2 to the power of
53 (i.e. 9007199254740992), beyond that some integers must be
represented as approximations, and your number is beyond that.

Richard.
 
R

RobG

I realize that numeric accuracy is not perfect in JS but from what I
have read in the FAQ etc. it seems that the number 632769996261406250
should be easily handled by JavaScript.

The following:
alert(632769996261406250)

Displays 632769996261406200 ... does anybody know why?

Richard gave you the precise answer, a rule of thumb is that integers
longer than 15 digits may be approximated.
 
M

Mike Ratcliffe

Richard gave you the precise answer, a rule of thumb is that integers
longer than 15 digits may be approximated.

Integers longer than 15 digits eh? I learn something new every day.

Thanks guys.
 
D

Dr J R Stockton

In comp.lang.javascript message <e569280f-ff26-4817-b5b8-c12ecf98107b@q2
2g2000yqm.googlegroups.com>, Wed, 11 Aug 2010 10:59:23, Mike Ratcliffe
I realize that numeric accuracy is not perfect in JS but from what I
have read in the FAQ etc. it seems that the number 632769996261406250
should be easily handled by JavaScript.

The following:
alert(632769996261406250)

Displays 632769996261406200 ... does anybody know why?

Yes. Convert your number to binary, getting
+100011001000000011001111010110000011101011111011011000101010
which is 60 bits long. Disregard trailing zeroes, and you have 59 bits
of resolution; a JavaScript Number, which is an IEEE Double, can hold
only 53 significant bits of resolution.

More about Numbers, etc., via sig below.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top