Why is this happening to me?? I multiply the same numbers in python and chrome's JS console but it seems as if JS has forgotten how to calculate.
Asked
Active
Viewed 1,048 times
1
-
http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html – adeneo Jan 02 '14 at 11:02
-
@ericbn then why is this happening?? – Shaurya Gupta Jan 02 '14 at 11:04
-
2Overflow, my friend, overflow... Python is a bit smarter then JavaScript when it comes to big numbers. – freakish Jan 02 '14 at 11:06
1 Answers
7
Python integer numbers are long ints.
JavaScript numbers are (double) floating points. The largest accurate JavaScript integer value is 2^53:
9007199254740992
Your number exceeds this value. If you need to handle integers accurately in JavaScript over the floating point threshold you need to some big number library.

Community
- 1
- 1

Mikko Ohtamaa
- 82,057
- 50
- 264
- 435
-
-
@wim: take it up with IEEE, they defined the behavior of floating-point types once precision is lost – Steve Jessop Jan 02 '14 at 12:50