what you mean by 1.11xxxxe-308
should be 2.22xxxxe-308
, which is called "regular form". There is also an "unconventional form" whose minimum absolute value is 4.9xxxxe-324
. This is all explained in IEEE754.
since it is JS, let's use the term in the JS standard. 64-bit floating-point type, symbol bit 1 bit, exponential bit 11 bit, Mantissa 52 bit.
first of all, the index, 11 digits, a total of 2048 kinds of values, come up with two kinds of values (there are still 2046 median values left), which denote 0, NaN positive and negative infinity, and a class of irregular numbers.
Let's talk about the first three cases first. If the index is 0, all 0 means 0
(according to the symbol bit, there will be positive and negative 0, two expressions), the index is 2047
not all 0 means NaN
(so NaN has many ways to express it), the index is 2047
digits all 0 means Inf
infinity.
then comes the representation of normal numbers, which are numbers that can be written in the form of squarm * 2 ^ e
, but require 2 ^ 52 < = m < 2 ^ 53
& & -1074 < = e < = 971
(there are exactly 2046 cases, which are different from those of IEEE754 and will be explained later). From the above conditions, we know that m
occupies 53 bits, but the maximum is always 1
, so remove it and save only the later 52bit, so we save the m of 53bit with 52bit.
finally is an irregular number, which can still be written in the form of squarm * 2 ^ e
, but requires m < 2 ^ 52
& & e = =-1074
. For this kind of number, m
can be expressed as 52bit, but the index can be expressed as 0
. But this value represents e =-1074
. For a normal number, we know that it has a binary significant number of 53
bits, which is converted to a decimal significant number of 15 to 16 digits, but the non-normal number is less than this value.
so the largest number is m = 2 ^ 53-1
& & e = 971
, that is, (2 ^ 53-1) * 2 ^ 971 = 1.79769313486e308
therefore, you think the algorithm of the maximum number is incorrect, although the first few digits are very similar to
.
// 2^1024-1 =
179769313486231590772930519078902473361797697894230657273430081157732675805500963132708477322407536021120113879871393357658789768814416622492847430639474124377767893424865485276302219601246094119453082952085005768838150682342462881473913110540827237163350510684586298239947245938479716304835356329624224137215
// (2^53-1) * 2^971 =
179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368
minimum number. For a normal tree, it is 2 ^ 52 * 2 ^-1074 = 2.22507e-308
, and the irregular number is 1 * 2 ^-1074 = 4.9406e-324
.
finally, in IEEE754's statement, for the normal number sqm* 2 ^ e
, it can be written as s * (m / 2 ^ 52) * 2 ^ (eBay 52)
. In this case, the Mantissa is from 1.000. ~ 1.11111. For a decimal such as
, minus the previous 1
is a number between 0x1. The range of eBay 52 is -1022 percent 1023
, which is what IEEE754 calls it.