I have been told that 1e100 is not exactly representable as a 64 bit floating point number. With a 64 bit floating point number, we can have 16 significant digits in the significand, and manipulate the exponent (up to about 10^308). Thus, as 1e100 has only one significant digit, why is this number not exactly representable as a floating point number?
Asked
Active
Viewed 213 times
0
-
1examine what it takes to represent 100, 1000, 10000, and then answer becomes obvious very fast. – old_timer Jul 03 '22 at 14:53
-
Its a topic from computer science that if you really want to know then you have to dig into the math. Otherwise - you just believe it (only powers of two can be represented in floating point) - see: [why-are-floating-point-numbers-inaccurate)](https://stackoverflow.com/questions/21895756/why-are-floating-point-numbers-inaccurate), [floating point arithmetic](https://ece.uwaterloo.ca/~dwharder/NumericalAnalysis/02Numerics/Double/paper.pdf), [floatingpoint](https://docs.python.org/3/tutorial/floatingpoint.html) and hundreds of articles like them (long and short) – topsail Jul 03 '22 at 14:54
-
floating point is base 2 not base 10. – old_timer Jul 03 '22 at 14:55
2 Answers
3
1e100
or 10100 is the same as 2100 * 5100.
5100, an odd number, is a 233 bit integer, far beyond the precision capabilities of a common 64-bit binary floating point - which often has 53 bits of precision. Each binary floating point has an exact value that is some integer times a power of 2.
If we are using a less common decimal floating point encoding, no problem to save 10100 exactly.

Paul Floyd
- 5,530
- 5
- 29
- 43

chux - Reinstate Monica
- 143,097
- 13
- 135
- 256
1
Floating-point uses exponents of 2 not 10.
10^100 ~ 1.1429873912822749822157835483053 x 2^332.
Conversely, though 2^332 has 99 significant digits, it can be represented exactly as a float.
-
might be worth pointing out that the f64 nearest to 1e100 is exactly `5147557589468029 * 2^(332-52)`, and matches to the expected 16 decimal places. `5147557589468029 * (2^-52)` matches your `1.14..., but your decimal approximation might be obscuring the representation – Sam Mason Jul 04 '22 at 19:13
-
@SamMason: no, the floating-point representation uses a mantissa that exceeds 1, not the nearest approximation. Also, showing an integer seems to imply an exact value. Your comment is obscuring things. – Jul 04 '22 at 19:53