3 ms·
> This doesn't give you any more precision than using floats directly, just a wider 'mantissa' range. I think this analysis misses a deep and important point.
by haberman 8y ago
> This doesn't give you any more precision than using floats directly, just a wider 'mantissa' range.
I think this analysis misses a deep and important point. The library you linked uses decimal floating point (in software) instead of the binary floating point used by IEEE floats.
The point of this is not to increase overall precision. A double is already precise to 2e-14% of its value, which means it's capable of representing something like $1 Trillion before it will get off by a whole cent.
The point of using decimal floating point is that it can exactly represent the values we care about when dealing with currency. This allows us to have no error, instead of trying to keep our error small. It means we never have to round (unless performing division).
You could have 1000x the precision in binary floating point, and decimal floating point would still be better for money.
- smallnamespace 8y ago> This allows us to have no error That's not true, because the software 'mantissa' in that library still only has 52 bits of precision (2e-14%). E.g. if you try to add $100 trillion + $0.01 using dinero.js, you still get underflow and the $0.01 disappears.