Re:Is Cobol holding you hostage with Math?
by boomlinde on Sunday July 29, 2018 @06:08AM
(#17637328)
Floating 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.
The 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".
Floating point numbers behave like rational numbers _with denominators that are powers of 2 only_.
All 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.
Re:Is Cobol holding you hostage with Math?
by boomlinde on Sunday July 29, 2018 @02:22PM
(#17639505)
1/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.
Re:Is Cobol holding you hostage with Math?
by quietbritishjim on Sunday July 29, 2018 @06:01AM
(#17637313)
I'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).
Re:Is Cobol holding you hostage with Math?
by slaymaker1907 on Sunday July 29, 2018 @11:55AM
(#17638726)
For 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.
Re:Is Cobol holding you hostage with Math?
by simonbyrne on Monday July 30, 2018 @03:53PM
(#17647435)
Conversely, the worlds most widely used financial software (Microsoft Excel) uses binary floating point under the hood.
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.