3 ms·
Some numbers do not have an exact representation in IEEE754. This leads to problems such as: > 1.03 - 0.42 0.6100000000000001
by partycoder 8y ago
Some numbers do not have an exact representation in IEEE754. This leads to problems such as:
> 1.03 - 0.42
0.6100000000000001
- deleted 8y ago[deleted]
- dchest 8y agoThese are not integers! Integers are exactly represented from -2^53-1 to 2^53-1.
- partycoder 8y agoYou claim that as long as numbers fit in a double precision IEEE754 floating point number significand, which is what JS implements, you are safe. Fine. But what happens after successive operations? the risk increases. Is this a good idea when dealing with currency? No. Does this library warn you about those cases or throw an error? no. Does this library provide unit tests for those cases? no.
- dchest 8y agoI agree that this library doesn't looks good — a proper implementation would use a better precision (e.g. 1/10000 of a currency unit) rather than "cents" (1/100), and of course, check ranges and the absence of fractions (Number.isSafeInteger).