2 ms·
In IEEE 754 standard, floating point numbers are represented using 1 bit for the sign, 11 bits for the exponent, and the remaining 52 bits for the fraction (num
by tomp 14y ago
In IEEE 754 standard, floating point numbers are represented using 1 bit for the sign, 11 bits for the exponent, and the remaining 52 bits for the fraction (number between 0 and 1). The exponent 7FF (in binary: all ones) is reserved for special values: NaN and infinity. If the fraction is 0 (all zeroes), then the number is +/- inf, otherwise it is a NaN.
NaN-tagging works by using the unused variations of NaN for pointers. The trick is that most processors only generate a single binary pattern for NaN, so all other binary patterns are never used to represent floating point numbers, and can thus be used to represent pointers. This works since the current x64 implementations only use 48 bits for the pointers, so all pointers can "fit" into the remaining 52 bits of NaN.
- lutusp 14y ago> In IEEE 754 standard, floating point numbers are represented using 1 bit for the sign, 11 bits for the exponent, and the remaining 52 bits for the fraction (number between 0 and 1). On reading this I immediately read the standard, hoping to discover that the word "fraction" wasn't used, only to find that "fraction" is defined as the part of the significand (mantissa) lying to the right of the implied binary point. In essence then (because the bit to the "left" of the binary point is only ever implied, never explicit), "fraction" stands as a synonym for significand. Unfortunate terminology. And why? Here's why: A fraction: 1/3 A significand, base ten: 0.3333333333333333 IEEE 754 can provide the second, but it cannot provide the first. IEEE 754: http://kfe.fjfi.cvut.cz/~klimo/nm/ieee754.pdf http://kfe.fjfi.cvut.cz/~klimo/nm/ieee754.pdf Significand: http://en.wikipedia.org/wiki/Significand http://en.wikipedia.org/wiki/Significand A quote: "The significand (also coefficient or mantissa) is part of a floating-point number, consisting of its significant digits." p.s. this is not a correction, it's a lament.
- tomp 14y agoIt's actually even more complicated... Remember, this is binary, so the only possible digits are 0 and 1. For example, 1/3 in binary is 0.01010101010101...; Encoding that in "floating point", we first get: 1.0101010101 * 2^-2; We can see that in this format, the first digit of the number is always 1; thus, the first digit of the significand, for any number, is ALWAYS 1 (in binary)! IEEE754 makes the optimization to not store this leading 1 as part of the fraction, so the the approximation to 1/3 is actually encoded as: 0 01111111101 0101010101010101010101010101010101010101010101010101 ^ ^ ^ | +-----+ | sign bit | fraction = 1.33333... = 1.01010101010101...0101010101010101b | |--- this part is included ---| | exponent = 01111111101b - 1023 = 1021 - 1023 = -2