3 ms·
If you want to replace floats, what with? Symbolic computation is way too expensive. Fractions are good whilst they're restricted in size but are too slow at
by Veedrac 12y ago
If you want to replace floats, what with?
Symbolic computation is way too expensive.
Fractions are good whilst they're restricted in size but are too slow at arbitrary precision and too inaccurate with numbers not centred on 1.
Fixed precision decimal floating point has numerical problems because numbers scale by too large an increment. (see footnote)
Arbitrary precision floats don't solve anything unless your problem was too little precision - with the precision of a 64 bit float this is rarely the case and 128 bits is massively more than that.
Arbitrary precision decimals don't solve anything either.
Logarithmic number systems are a good contender but almost all operations become
lossy. This is OK if you're using them as approximations - which is the common use of floats - but the fact floats are exact on the integers up to a large ceiling is useful (see Javascript) as with many other of their exactness properties.
Even better might be a symmetric level-index number system; you get the advantages of logarithmic number systems but also get immunity from overflow and underflow - the only operation that isn't closed is division by 0 and since operations can't underflow all 0s are actually 0.
If it were me implementing a new very-high level language with only weak cares about speed (eg. faster than doing it symbolically), I'd probably choose to use fixed precision fractions that fall back to symmetric level-index numbers instead of rounding. That way I'd get precise rationals (including int64s), immunity from underflow and overflow and a smoother error curve than floats.
---
Some people are pretty surprised to hear me criticize decimal types, but they're genuinely numerically worse than binary floating point. I've talked about this in depth here:
http://www.reddit.com/r/programming/comments/2ut00j/a_little_thing_to_love_about_perl_6_and_cobol/cobl3vd http://www.reddit.com/r/programming/comments/2ut00j/a_little...
and I give a rough rule-of-thumb about what type to use when here:
http://www.reddit.com/r/learnpython/comments/2wyeho/is_this_an_error_in_the_python_interpreter_if_not/covafmk http://www.reddit.com/r/learnpython/comments/2wyeho/is_this_...