timonsku
timonsku

Reputation: 1258

Why is Javascript's MAX_VALUE an "approximate" according to ECMA

The value of Number.MAX_VALUE is the largest positive finite value of the Number type, which is approximately 1.7976931348623157 × 10308.

Source

Why "approximately"? Can we not know for sure that this is indeed the maximum positive numeric value? The answers in this question seem to prove this quite well. Or does approximate mean something different in this context?

Upvotes: 1

Views: 109

Answers (2)

jillro
jillro

Reputation: 4569

First, you would not want to write a number with 308 digits. There are probably further numbers after the coma, which are not written, and this is the reason it is an approximation.

Second, the Number object can not take all the values between 0 and 1.7976931348623157 × 10^308. It can take all the values between +- 0 and 2^53. For bigger values, it stores a number smaller than 2^53 and an order of magnitude. So you cannot have unit precision, unless the number you want to store happens to be exactly of the form x * 2^e.

Still the biggest number you can store is precisely (2^53 - 1) * 2^971, which approximately equals 1.7976931348623157 * 10^308, which is much easier to read.

(So, get me right, "First" is the real reason, and "Second" is just an explanation of what is the exact value.)

Source : http://www.ecma-international.org/ecma-262/5.1/#sec-8.5

Upvotes: 3

Niet the Dark Absol
Niet the Dark Absol

Reputation: 324750

The exact value of MAX_VALUE is:

179,769,313,486,231,570,814,527,423,731,704,356,798,070,567,525,
844,996,598,917,476,803,157,260,780,028,538,760,589,558,632,766,
878,171,540,458,953,514,382,464,234,321,326,889,464,182,768,467,
546,703,537,516,986,049,910,576,551,282,076,245,490,090,389,328,
944,075,868,508,455,133,942,304,583,236,903,222,948,165,808,559,
332,123,348,274,797,826,204,144,723,168,738,177,180,919,299,881,
250,404,026,184,124,858,368

Does this mean anything more to you than "approximately 1.7976931348623157 × 10308"?

Upvotes: 6

Related Questions