Floating-point numbers
The topic Duality ended with certificates: a primal point, a dual point and a gap that bounds how far both are from the optimum. Every number in such a certificate, like every gradient, solve and decomposition in this course, is computed in floating point. This topic asks how many digits of an answer survive.
A floating-point number stores a fixed number of significant bits and an exponent, like scientific notation in base 2. The gap between and the next representable number is the machine epsilon . Each arithmetic operation returns the exact result rounded to the nearest representable number:
So a single operation is accurate to a relative error of about . The formats used in ML differ a lot:
| Format | Significant bits | Largest number | |
|---|---|---|---|
| float64 | |||
| float32 | |||
| bfloat16 | |||
| float16 |
A relative error of leaves the first decimal digits intact, so float64 carries about significant digits.
Two consequences show up everywhere. First, adding to a positive number smaller than half the gap between and the next representable number changes nothing. Right after that gap is , so in float64 1 + 1e-16 == 1 is True. Second, the range is finite. exp(710) is already inf in float64, and exp(89) is inf in float32.