Real Number Representation¶
Fixed Point¶
It's a known fact that we can't store decimals in a computer. Therefore, we'd like a function that maps from \(R \to Z\). Consider the numbers 41.50, 2.3, and 11.503. Is there a consistent function that would map all of them to integers? Well yes! \(f(x) = 1000x\) gets that job done. We can impose a fixed number of digits after decimal point, and convert all numbers to hit that (either by appending 0s or truncating).
\(41.50 = 41500 * 10^{-3}\)
Hold on, this looks quite a lot like the IEEE 754 representation up ahead right? However, in this representation, \(-3\) is fixed, and shared by all numbers belonging to this datatype. This is why we call the position of the decimal point as fixed.
Floating Point¶
Contrary to this, floating point representation does not make such an assumption. In this, the decimal point is allowed to float.
Images courtesy of GeeksForGeeks.
Call the mantissa M, exponent E, and sign S
\(N = -S * 2^{E-127} * (1+M)\)
for single precision floating point numbers.
Edge Cases¶
S | E | M | Result |
---|---|---|---|
X | 0 | 0 | 0 |
+ | 255 | 0 | +Inf |
- | 255 | 0 | -Inf |
X | 255 | !0 | NAN |
X | 0 | !0 | Denormal |
X means that the sign is irrelevant.