3 ms·
The question is can computers do arbitrary precision arithmetic. Technically you'd need infinite memory, but if you use fractions to represent amounts, as is co
by black-tea 8y ago
The question is can computers do arbitrary precision arithmetic. Technically you'd need infinite memory, but if you use fractions to represent amounts, as is correct, then practically speaking, yes you can. One accounting system that uses fractions is ledger[0].
[0] https://www.ledger-cli.org/ https://www.ledger-cli.org/
- JoeAltmaier 8y agoSix or seven digits of precision (like all floating point) is good enough, and far better than exactly 2 digits of decimal. Millions of times better. Fractions do little for interest rates, which are transcendental functions and sometimes even irrational.
- paulie_a 8y agoIf you are using floats in financial transactions you are doing it incredibly wrong. Never use floating points for that, ever. It is insanely problematic and bug prown.
- JoeAltmaier 8y agoYes it doesn't match the ad-hoc stuff finance people do. That's in fact my point.
- dmoy 8y agoThat's not how floating point works though. The precision is by definition floating. With a sufficiently large number, your least significant bit of precision might be in the 10s or 100s or more of dollars (or whatever currency). Your issue then is that if you combine a large enough number with anything, then you get precision loss and money just starts disappearing (or appearing out of nowhere). Even if your hyperinflation was over ten orders of magnitude less bad than Zimbabwe's (decimal orders of magnitude even), you would run into floating point precision loss with a 64 bit floating point number.
- JoeAltmaier 8y agoA double has 15 digits. Which counts more money than exists anywhere added up. Not a problem I'm thinking?
- jimktrains2 8y agoAnd ieee floating point still can't store 10¢ exactly.
- dmoy 8y agoI dunno, South korea's M2 would need 17 or 18 digits to represent I think. Edit: Japan too. Say south korea has a few years of hyperinflation, not even anywhere close to zimbabwe bad, and you'd have money disappearing right & left.
- roywiggins 8y agoIt isn't enough. Suppose you have something in dollars and cents (in a float), and you want a count of pennies. 2.22 * 100.0 == 222.00000000000003, not 218.0. This is a) wrong and b) not an integer. Either you are aware of this and manually round the result to an integer, or you use fixed-point math.