4 ms·
Daily reminder: floats are emulated reals. Money values are rationals, not reals. Languages need to support the full number stack, including the rationals! "
by otabdeveloper2 8y ago
Daily reminder: floats are emulated reals.
Money values are rationals, not reals.
Languages need to support the full number stack, including the rationals!
"Floating point decimal" is wrong and the worst of both worlds. Unless you live in the USA, you need to do currency conversions anyways, and those aren't decimal.
- quietbritishjim 8y agoI'm not sure I exactly disagree with "floats are emulated reals" but it is certainly clearer to say that "floats are rationals, not reals, but only support denominators that are powers of 2". Then "money values are rationals, but their denominators are powers of 10" (usually).
- boomlinde 8y agoFloating point numbers are all rational. Given that rational numbers are a countable subset of real numbers, I think it's inaccurate to say that floats are somehow "emulated reals" as opposed to rationals. The radix of a floating point number relates to the quotient of a rational number. For example in decimal floating point significand-base-exponent form, 1.23 is 123 * 10^-2 or 123/100.
- taejo 8y agoAll floating point numbers are rational, but not all rational numbers are floating-point, including very simple ones like 1/3, and ones common in finance like 1/100, which is the point.
- mlvljr 8y agoFixed or floating?
- boomlinde 8y ago1/3 and 1/100 are perfectly representable using floating point. Sure, I've never seen fp in base 3 in the wild, but base 10 isn't unusual for the exact reason you're pointing out. So what I see is a conclusion that floating point is "emulated reals" as opposed to rationals, despite all floating point numbers being rational numbers and that decimal floating point is wrong and "the worst of both worlds", but I don't see a valid argument for it.
- m314 8y agoThe operations on floating point numbers do not behave like rational numbers. Floating point 1.0/3.0 is not equal to the rational 1/3. It's the same up to a margin of error, yes, but that's where the emulation part comes in. It would also be fair to say that floating point numbers are "emulated rationals".
- rhaps0dy 8y agoFloating point numbers behave like rational numbers _with denominators that are powers of 2 only_.
- slaymaker1907 8y agoFor infrastructure, rationals can be kind of dangerous due to unexpected memory spikes. For instance, multiplying 47/33 by 33 actually decreases the memory required to store the value in contrast to big integers which always increase in storage size as the number gets larger.
- simonbyrne 8y agoConversely, the worlds most widely used financial software (Microsoft Excel) uses binary floating point under the hood.