Alex Mathew
Alex Mathew

Reputation: 4225

Why is Number.MAX_VALUE 1.7976931348623157e+308 instead of 9007199254740992e+1024?

JavaScript uses IEEE 754 for storing numbers, for both integer and floating point values, where 53 bits are used for representing the mantissa and 11 bits are used for representing the exponent.

The maximum value representable with a signed 53 bit integer is ±9007199254740992, and the maximum value representable with a signed 11 bit integer is ±1024.

However, Number.MAX_VALUE in JavaScript is 1.7976931348623157e+308. Why isn’t it 9007199254740992e+1024, which is possible to represent with 64 bits and is the larger value?

Upvotes: 10

Views: 25073

Answers (4)

Ganesh Kumar
Ganesh Kumar

Reputation: 1

Well, it could be represented like 1024e+9007199254740992 too it is also 64 bit cause 1024 is 11 bit and 9q is 53 bit and 11+53=64

Upvotes: -1

Luna Wang
Luna Wang

Reputation: 21

The actual answer is (2^54 - 1)/2^53 *(2^1023). Look it up on Wikipedia! (Double precision floating point format

Upvotes: 2

user395760
user395760

Reputation:

The AeB syntax mirrors scientific notation and hence means A * 10^B, not A * 2^B. The maximum binary64 value is 9007199254740992 * 2^1024 (or something like that), not 9007199254740992 * 10^1024. Your proposed 9007199254740992e+1024 means the latter and is much larger (10^1024 ~= 2^3402), so it doesn't actually fit in a 64 bit binary float (try it!).

Upvotes: 12

Aki Suihkonen
Aki Suihkonen

Reputation: 20037

The scientific notation e+308 means 10^308, which is about 0.5562*2^1024.

Upvotes: 3

Related Questions