JavaScript’s Defects on Numbers

Number larger than 0×20000000000000 (54bit) will not be reliable.

Here is the test script:

javascript:alert (0x1ffffffffffffe);
javascript:alert (0x1fffffffffffff);
javascript:alert (0x20000000000000);
javascript:alert (0x20000000000001);

You can see that the latter two numbers are same number in JavaScript!


The safe number range for integer is “-0x1fffffffffffff – 0x1fffffffffffff” (53bit). Therefore, in Java to JavaScript world, conversion of Java’s long number to JavaScript’s Number may result in incorrect calculations.

This entry was posted in JavaScript. Bookmark the permalink.

8 Responses to JavaScript’s Defects on Numbers

  1. I won’t debate along with your conclusions simply I feel you are exact on the money! You’ve come up with a valid case for your sentiments and now I know much more this unusual subject. Thank you this outstanding publish and that i will arrive again for additional.

  2. Chris says:

    That would be because all numbers in javascript are actually 64 bit floating point.
    Not all integers higher than 53 bits can be exactly represented as a 64 bit floating point value, hence 0×20000000000000 and 0×20000000000001 are the same.
    This is due to the 11 bit exponent and the 1 sign bit. This only leaves 52 bits to store the fraction

  3. First, let me commend your pellucidity on this subject. I am not a pro during this subject, but after reading your write-up, my knowledge has developed substantially. Please tolerate me to catch your rss nourish to remain in contact with any upcoming revisions. Pleasant career and will offer it on to pals and my weblog audience.

  4. gry dzieci says:

    Super witryna. Oby tak dalej.

  5. Your thought is not incorrect,I am guessing God helps those who aid themselves. Come on!

  6. Earlean Metzinger says:

    Nowadays to find a similar Efficient and Effective SEO Automation software at one Time payment of US 99-00 is a rarity\

  7. Hi there, just wanted to mention, I loved this article. It was inspiring.
    Keep on posting!

    Feel free to surf to my web blog: milwaukee Car accident attorney

  8. Hey there, I think your website might be having browser compatibility
    issues. When I look at your blog in Opera, it looks fine but when opening in Internet Explorer, it has some
    overlapping. I just wanted to give you a quick heads up!
    Other then that, great blog!

    Feel free to visit my web page – auto accident attorney fort lauderdale

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>