5

All numbers in Javascript are 64bit (8 bytes) floating point numbers but why the effective range of JavaScript is 5e-324 (negative) to 1.7976931348623157e+308 (positive)?

2
  • From all the possible values, 9007199254740990 of them are represented as NaN (Not a number). Commented Apr 30, 2012 at 15:12
  • edwardpku, you should probably accept either MДΓΓ БДLL's answer or mine (depending on whether you find a pointer to the spec, or an explanation of why the spec says that, more helpful). Commented May 2, 2012 at 9:27

2 Answers 2

8

Because that is what is defined by the IEEE 754 spec.

0x 0000 0000 0000 0001 = 2⁻¹⁰²²⁻⁵² ≈ 4.9406564584124654 x 10⁻³²⁴ (Min subnormal positive double)
0x 000f ffff ffff ffff = 2⁻¹⁰²² - 2⁻¹⁰²²⁻⁵² ≈ 2.2250738585072009 x 10⁻³⁰⁸ (Max subnormal positive double)
0x 0010 0000 0000 0000 = 2⁻¹⁰²² ≈ 2.2250738585072014 x 10⁻³⁰⁸ (Min normal positive double)
0x 7fef ffff ffff ffff = (1 + (1 - 2⁻⁵²)) x 2¹⁰²³ ≈ 1.7976931348623157 x 10³⁰⁸ (Max Double)
Sign up to request clarification or add additional context in comments.

Comments

4

Because of denormal values; see e.g. http://en.wikipedia.org/wiki/Denormal_number. These extend the range of floating-point values to allow values closer to zero than would otherwise be possible.

You would be well advised to treat these as an implementation detail whose purpose is to make calculations with very small intermediate results not behave too pathologically; when you use these very small values some precision is lost.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.