This post describes many insane edge conditions that can trip you up when working with numbers in various programming languages.
I’m surprised that Rust prints the floating point f64 representation of 288230376151711744 as 288230376151711740, even though the former has an exact representation as a float. I agree with the author that Rust is lying to you, because it is choosing to print a trailing digit with the wrong value (0 instead of 4). It’s really a bug. Better behaviour is to print
2.8823037615171174e17
This is better because the final mantissa digit that is printed is 4, there is no following 0, and the use of scientific notation (rather than integer notation) signals that this is an approximate decimal representation.
One more example supporting my theory that, actually, nothing is simple. Great article.
This post describes many insane edge conditions that can trip you up when working with numbers in various programming languages.
I’m surprised that Rust prints the floating point f64 representation of 288230376151711744 as 288230376151711740, even though the former has an exact representation as a float. I agree with the author that Rust is lying to you, because it is choosing to print a trailing digit with the wrong value (0 instead of 4). It’s really a bug. Better behaviour is to print
This is better because the final mantissa digit that is printed is 4, there is no following 0, and the use of scientific notation (rather than integer notation) signals that this is an approximate decimal representation.