Tab cleanup time!
I’ve had this article on “explaining” floating point numbers in my phone’s browser for eons. Basically, my first glance made me go “huh” and I didn’t have the time or energy to figure it out at that moment and that’s what stuck with me.
But I need a post today and killing this tab suddenly was motivating.
One annoying thing about the article is that it doesn’t say what about floating point it’s explaining or why floating point works the way it does. It seems to be more about explaining how to convert from floating point notation in to standard decimal notation. Which…fair enough. I’m not sure the “scary formula” is such a problem or that the window metaphor is all that useful in the end. In the end, standard floating point is just scientific notation in base2 with a fixed width (thus a “moving” decimal point). If standard decimal scientific notation is confusing in the same way then maybe this visual/windowing explanation might help. But I’d start with scientific notation as most people will be a little familiar with it.
The big thing not quite explained is how (and why) various numbers are approximated and thus departures from various standard features of the rationals and reals. That seems to be the deep part of floating point, esp the bits that come from features of the base rather than features of the width.
Any rational number can be represented exactly as a pair (ie ratio!) of integers. The size of your integers constrain which rationals you can represent (ie max rational is maxint/1 and min (positive) rational (greater than zero) is 1/maxint). But in positional notations with a radix point (like standard decimal notation) we typically can’t capture all rationals because some rationals will have an infinite expansion. 1/3 in decimal, for example. (Though the decimal will be repeating.) Binary has a different set of numbers it can’t easily represent.
Ok the point of this isn’t to fully explain floating point but to get back to the idea that it has a lot of pieces so there’s a lot to understand. If you’re only going to explain a small piece of it say that! Say why this piece is useful to understand! Without this you’re problem typically making things worse.