3 ms·
This is an interesting article and worth a read. Then head over to Mike Cowlishaw's rant on decimal [1]. I met Mike at a conference and he's a brilliant guy, pr
by ChuckMcM 16y ago
This is an interesting article and worth a read. Then head over to Mike Cowlishaw's rant on decimal [1]. I met Mike at a conference and he's a brilliant guy, prior to seeing his decimal stuff I was using REXX on an Amiga (what Tcl might have been) which was language he invented while at IBM.
He got interested in decimal math early on but not because 'floats' such by binary floats really suck. That is a number system where .1 can't be accurately represented. How often do you use .1 in your calculations? He has a couple of examples of 34 digit precision which is representable in a 128 bit quantity. (3.7 bits per digit). Straight BCD would of course be 32 digits minus the digits which represent the exponent.
I wrote some CAD routines once that used decimal arithmetic rather than binary and was amazed at how much better it worked in terms of edges lining up and when you approximate non-square surfaces you get much better tesselation.
And of course for history buffs the IBM 1620 used decimal as a native representation for numbers. Now that we've got lots of transistors to play with, perhaps its a good time to revisit the way we represent numbers.
[1] http://speleotrove.com/decimal/ http://speleotrove.com/decimal/
- palish 16y ago"I wrote some CAD routines once that used decimal arithmetic rather than binary and was amazed at how much better it worked in terms of edges lining up and when you approximate non-square surfaces you get much better tesselation." That's precisely what I'm working on. What did you use? P.S. Use 0.125, not 0.100
- ChuckMcM 16y agoI used the Java decNumber class (linked off Mike's web site) and the Java 2D API. Once the 3D API came out it seemed like the visualization code at least should use that. Converting to/from decimals to floats was unnecessarily painful at the time.
- arundelo 16y agoI'd like hardware that represents fractional parts in binary-coded base-15 -- no rounding on 1/3 as well as 1/10!
- klodolph 16y ago1/10 would be a repeating number in base-15, 0.1777777... (Well, technically, 1/10 is not a repeating number in any base, but you know what I mean.)
- arundelo 16y agoOops, you're right! I was misremembering something I had figured out once. It's base-30 that does multiples of 2, 10, and 3 (and 5 etc.). (And 30 is pretty close to a power of 2 so that not much space gets wasted if a BCD-like method is used where the underlying representation is base-2.)
- jules 16y agoThat seems downright stupid. "How often do you use 1/3 in your calculations. Base 10 is a number system where 1/3 can't be accurately represented." If you need exactness, use rationals. Don't just use a number system with more prime divisors. If you don't need exactness, use base 2.