Re:Determinism with fixed point math
by lotyrin on Friday July 10, 2015 @02:50PM
(#9865957)
It's kinda poignant to think of the rediscovery of the option to -not- use a feature.
It drives home that floating point has come to feel normal and the default mode of doing anything and everything with a decimal point regardless of its suitability to people's actual problems.
It reminds me of the many bugs I've fixed in web e-commerce code using floats and accumulating rounding error with discount maths and the sad conversations with the bug's authors afterward.
It's unfortunate more developers aren't introduced to full-featured bignums and arbitrary precision first, that more languages don't use them by default before offering machine numbers (and decently usable implementations of patterns atop them like fixed precision) with their many caveats (nondeterminism, signing, imprecision, overflows) as optimizations one can choose -when- appropriate.
There are just so many developers (especially of business software) who are liberally consuming memory and CPU instructions to ultimately display these numbers with UI toolkits and constraints algorithms or HTML, CSS abstractions etc. but accidentally refusing (through ignorance and ancient[-in-terms-of-IT] momentum) to ever use more than the tiniest resources to actually precisely and deterministically calculate them.
Re:Determinism with fixed point math
by nonononyes on Friday July 10, 2015 @03:49PM
(#9866316)
Yes, one should never, ever use floats to handle currency values. Since currencies round to decimal digits, one should use decimal numbers. Databases that store currency values have a "decimal" type too. Using integers works, but have caveats:
Some programming languages, like Haskell, default to Bignums (or Rationals for numbers that aren't integers) unless you ask for something else. I think that's a good default.
Re:Determinism with fixed point math
by sago on Friday July 10, 2015 @04:44PM
(#9866603)
Ah brings back memories! Nice to see old techniques rediscovered.
If the OP is reading, then please add a license to your repo. Github even nags you about it now, but there's no excuse, even if you want to make it proprietary.
It drives home that floating point has come to feel normal and the default mode of doing anything and everything with a decimal point regardless of its suitability to people's actual problems.
It reminds me of the many bugs I've fixed in web e-commerce code using floats and accumulating rounding error with discount maths and the sad conversations with the bug's authors afterward.
It's unfortunate more developers aren't introduced to full-featured bignums and arbitrary precision first, that more languages don't use them by default before offering machine numbers (and decently usable implementations of patterns atop them like fixed precision) with their many caveats (nondeterminism, signing, imprecision, overflows) as optimizations one can choose -when- appropriate.
There are just so many developers (especially of business software) who are liberally consuming memory and CPU instructions to ultimately display these numbers with UI toolkits and constraints algorithms or HTML, CSS abstractions etc. but accidentally refusing (through ignorance and ancient[-in-terms-of-IT] momentum) to ever use more than the tiniest resources to actually precisely and deterministically calculate them.
http://floating-point-gui.de/formats/integer/
Some programming languages, like Haskell, default to Bignums (or Rationals for numbers that aren't integers) unless you ask for something else. I think that's a good default.
If the OP is reading, then please add a license to your repo. Github even nags you about it now, but there's no excuse, even if you want to make it proprietary.