Monday, April 28, 2014

Binary fractions bit Donald Knuth!

Binary fractions bit Donald Knuth!  At infrequent intervals, Donald Knuth publishes notes on TeX updates.  Even though I haven't used TeX for years, I always read these because, well, Knuth.  This one has a passage that tickled my fancy, as it's about one of my own pet peeves: the use of binary fractions (including binary floating point numbers).  It seems that Donald Knuth, one of the pantheon of computer science gods, was bitten by them, too:
I made the foolish mistake of using binary fractions internally, while providing approximate decimal equivalents in the user interface. I should have defined a scaled point to be 1/100000 of a printer's point, thereby making internal and external representations coincide. This anomaly, which is discussed further in [5], is the only real regret that I have today about TeX's original design.
The gods are fallible, too :)

Companies I worked for have been burned by this issue a surprising number of times.  The most memorable case I ran into was a company that implemented an electronic stock and option trading platform that used binary floating point math to hold monetary values.  Big, big problems resulted.  To fix it, I had to do battle with a dozen or so senior engineers – very experienced and generally competent folks – who had a great deal of trouble accepting the simple fact that binary floating point numbers are incapable of exactly representing a great many decimal fractions...

No comments:

Post a Comment