2 ms·
2/3 === .666666666666666629659232512495 is probably worse, because it can seduce you into thinking it's accurate. Why is `2 / 3 * 3 === 3`, but `1 / 3 * 3 < 3`?
by ridiculous_fish 9y ago
2/3 === .666666666666666629659232512495 is probably worse, because it can seduce you into thinking it's accurate. Why is `2 / 3 * 3 === 3`, but `1 / 3 * 3 < 3`?
JS's floating-point-or-bust, combined with some weird Math semantics, makes it challenging to write numerically correct functions.
- bcherny 9y agoThat's a fair point. Which language do you think does it better, or is there a library you like to use (eg. Haskell's scientific type)?
- ridiculous_fish 9y agoFloating point tends to break all sorts of assumptions. For languages without static types, bignum integers and distinct operators for truncating vs FP division is probably best. This is how Python 3 works, plus Haskell and SML (with static types).