5 ms·
Hah! If Mike Cowlishaw was here he could give you a wonderfully eloquent treatment on why binary floating point sucks. And he's actually done something about it
by ChuckMcM 14y ago
Hah! If Mike Cowlishaw was here he could give you a wonderfully eloquent treatment on why binary floating point sucks. And he's actually done something about it [1] with both a format and software to deal with decimal numbers.
Further the densely packed form gets very close to optimal in terms of bit representation. Assume that 4 bits (BCD) is 'worst' case, you can represent 0-9 but you 'waste' the information space 'a-f' (in hex, 10-15 in decimal) but 3 bits only gives you 8 states. What you want is a total of 10 states which is 3.3125 bit's worth (best case) or 3 digits in 9.9375 bits, these formats give you 3 digits in 10 bits which is pretty close.
Mike goes on to talk about how to build hardware that does floating point operations on this stuff. I built some into an FPGA and it really is pretty straight forward, especially if you do iterative multiply and divide.
Consider the interesting thing where you take 128 bits (two 64 bit words) where you use 60 bits for the whole part (18 digits) and 60 bits for the fractional part (18 digits) and you've got 8 bits left over for various non-number entities (+inf, -inf, NaN, etc). Would be great for CAD package, or a financial spreadsheet.
[1] http://speleotrove.com/decimal/DPDecimal.html http://speleotrove.com/decimal/DPDecimal.html
- matthiasl 14y agoThat was an interesting link, thanks. I liked other parts of the site too, for instance http://speleotrove.com/decimal/ http://speleotrove.com/decimal/ Any idea what decimal floating point is used for? (I have little to no idea about CAD or financial software. I can see that fixed-point decimal with two decimal places is useful for things where you want to be able to reason about rounding of cents. I can also see that you'd want more than two decimal places for a lot of calculations, for instance computing interest. But decimal floating point...what's specified in such a way that you need to use decimal floating point? I checked the wikipedia decimal floating point page. Didn't see any concrete examples there either.)
- ChuckMcM 14y agoIt is used in high end CAD systems where tolerances need to be exact, there was also a wonderful decimal package for COBOL which was doing financial computations. Unknown to many (most?) people some early IBM Mainframes [1] were decimal machines. If you work in 3D modeling you will be familiar with the effects of binary floating point as 'gaps' between polygons where they shouldn't be. Sometimes those gaps only appear at a certain scale because that is where the rounding gets it wrong, or if you compensate by always rounding up you get overlaps or texture issues. [1] http://en.wikipedia.org/wiki/IBM_700/7000_series#Decimal_architecture_.287070.2F7072.2F7074.29 http://en.wikipedia.org/wiki/IBM_700/7000_series#Decimal_arc...