Created
July 10, 2011 01:57
-
-
Save whatgoodisaroad/1074157 to your computer and use it in GitHub Desktop.
JavaScript Primitive Numbers have Fixed Precision
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Numbers with many significant figures may be truncated: | |
| var primitive = 2.00000000000000000000000000000000000001; | |
| // Immediately after creation, the low digits are truncated away. | |
| primitive; | |
| // = 2 | |
| // Performing math on primitives will not include truncated digits. | |
| primitive * 2; | |
| // = 4 | |
| // In the case of PI, only 16 digits are preserved. | |
| var pi = 3.1415926535897932384626433832795028841971693993751058209749445923078164062; // ... | |
| pi; | |
| // = 3.141592653589793 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment