https://medium.com/@bellmar/is-cobol-holding-you-hostage-with-math-5498c0eb428b
Face it: nobody likes fractions, not even computers.
When we talk about COBOL the first question on everyone's mind is always Why are we still using it in so many critical places? Banks are still running COBOL, close to 7% of the GDP is dependent on COBOL in the form of payments from the Centers for Medicare & Medicaid Services, The IRS famously still uses COBOL, airlines still use COBOL (Adam Fletcher dropped my favorite fun fact on this topic in his Systems We Love talk: the reservation number on your ticket used to be just a pointer), lots of critical infrastructure both in the private and public sector still runs on COBOL.
Why?
The traditional answer is deeply cynical. Organizations are lazy, incompetent, stupid. They are cheap: unwilling to invest the money needed upfront to rewrite the whole system in something modern. Overall we assume that the reason so much of civil society runs on COBOL is a combination of inertia and shortsightedness. And certainly there is a little truth there. Rewriting a mass of spaghetti code is no small task. It is expensive. It is difficult. And if the existing software seems to be working fine there might be little incentive to invest in the project.
But back when I was working with the IRS the old COBOL developers used to tell me: "We tried to rewrite the code in Java and Java couldn't do the calculations right."
[Ed note: The referenced article is extremely readable and clearly explains the differences between floating-point and fixed-point math, as well as providing an example and explanation that clearly shows the tradeoffs.]
(Score: 2, Informative) by Anonymous Coward on Monday September 16 2019, @07:25PM (1 child)
Not vice versa. Any fraction that can be represented in binary can be represented in decimal.
The numbers that have terminating representation in binary are those that can be expressed as the sum of fractions where the denominator is a power of two. e.g. 0.140625 is the sum of 1/8 and 1/64. Or 5/16 + 9/128 + 23/256 = 0.47265625.
The numbers that have terminating representation in decimal on the other hand are those that can be expressed as the sum of fractions where the denominator is a power of two times a power of five (the factors of ten). So there are a lot of denominators that are available in base ten but not base two.
Of course rational numbers are rational, and irrational numbers are irrational, regardless (or irregardless ;) ) of the radix used. The numbers that don't have terminating representations have repeating representations instead. You can see this in the simple fractions that have repeating representations in decimal : they're the ones where the denominator is relatively prime to 2^n*5^m. 1/3, 1/6, 1/7, 1/9...
(Score: 3, Informative) by DannyB on Monday September 16 2019, @08:02PM
Thank you. That makes sense.
Terminating binary denominator must be power of 2.
Terminating decimal denominator must be power of 2 times power of 5.
This is excellent point to refute another reply that I trotted out the often used example of 0.1 not having an exact binary representation.
To transfer files: right-click on file, pick Copy. Unplug mouse, plug mouse into other computer. Right-click, paste.