Stories
Slash Boxes
Comments

SoylentNews is people

posted by martyb on Monday September 16 2019, @01:48PM   Printer-friendly
from the COBOL-is-often-fractionally-better dept.

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.]


Original Submission

 
This discussion has been archived. No new comments can be posted.
Display Options Threshold/Breakthrough Mark All as Read Mark All as Unread
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
  • (Score: 2) by FatPhil on Monday September 16 2019, @04:13PM (5 children)

    by FatPhil (863) <reversethis-{if.fdsa} {ta} {tnelyos-cp}> on Monday September 16 2019, @04:13PM (#894662) Homepage
    Now use decimal, and replace those 1000s with 1001, 1000000s with 1002001s, and report back.

    You see, if you want to do anything apart from multiply and divide by factors of powers of 10, you "are screwed before [you] start".

    No difference from binary. Read some Kahan (or at least /What ever computer scientist should know about floating point arithmetic/) before bloviating so.
    --
    Great minds discuss ideas; average minds discuss events; small minds discuss people; the smallest discuss themselves
    Starting Score:    1  point
    Karma-Bonus Modifier   +1  

    Total Score:   2  
  • (Score: 5, Touché) by bradley13 on Monday September 16 2019, @04:36PM (4 children)

    by bradley13 (3053) on Monday September 16 2019, @04:36PM (#894671) Homepage Journal

    The point is this: When you are doing financial calculations, you are using powers of 10. Because that's how currencies work.

    --
    Everyone is somebody else's weirdo.
    • (Score: 4, Insightful) by FatPhil on Monday September 16 2019, @05:58PM (2 children)

      by FatPhil (863) <reversethis-{if.fdsa} {ta} {tnelyos-cp}> on Monday September 16 2019, @05:58PM (#894729) Homepage
      False. You're thinking of noddy stuff like ledger accounting where the input numbers have been passed a priori through a filter that has simplified them to be trivial, and exactly handlable in decimal. This is only a subset of financial computations. If you can't imagine exponentiation to a non-integer power ever happening in the world of finance, then *put down the calculator, and walk away, you're not safe in charge of such a thing*. Or become president of the USA.
      --
      Great minds discuss ideas; average minds discuss events; small minds discuss people; the smallest discuss themselves
      • (Score: 2) by DannyB on Monday September 16 2019, @06:03PM (1 child)

        by DannyB (5839) Subscriber Badge on Monday September 16 2019, @06:03PM (#894733) Journal

        I have written calculations like you describe in a financial calculation. That calculation is a black box. It takes inputs, does an inexact calculation, to great precision, and then the results are fixed into some form of currency values that are the result(s) of that black box.

        Everyone who does the same calculations (different languages, implementations, etc) will get the same results. But outside that black box, you're back to some kind of currency representation of money.

        Values of money have always been integer data types since before recorded history. The age of computers did not change that.

        --
        The lower I set my standards the more accomplishments I have.
        • (Score: 2) by FatPhil on Tuesday September 17 2019, @07:05AM

          by FatPhil (863) <reversethis-{if.fdsa} {ta} {tnelyos-cp}> on Tuesday September 17 2019, @07:05AM (#895044) Homepage
          > Values of money have always been integer data types since before recorded history.

          I'd change that to "Values of money have always been values representing integer multiples of an atomic unit of value since before recorded history." as we've usually chosen a fixed point representation. If the base unit of currency was the cent, rather than the dollar, then many of the issues people bring up would simply evaporate. This is because decimal-heads love saying stupid things like "you can't represent $0.01 exactly in binary", which is patently false if you're representing cents. If you encounter side effects like "1 dollar (100)" * "1 dollar (100)" = "100 dollars (10,000)", then you are almost certainly doing something wrong, as there's no such thing as a square dollar.

          But you seem to get it - firstly you need an exact representation for every value that you wish to represent (can be fixed point, can be floating point suitably scaled, can be decimal FP, can be integer). Binary FP based on dollars is not such a beast - noone's denying that. Once you've got that, then operate on those values using whatever is most accurate. And given that you want to avoid overflow at all costs, that's almost certainly FP. And as I've mentioned elsewhere, binary provably does better than decimal.

          The problem is when people fail to perform that first decision-making step correctly. Some languages protect idiot programmers against this better than others. I personally think it's better to just not hire idiot programmers, as they'll make a mistake elsewhere.
          --
          Great minds discuss ideas; average minds discuss events; small minds discuss people; the smallest discuss themselves
    • (Score: 3, Informative) by DannyB on Monday September 16 2019, @05:59PM

      by DannyB (5839) Subscriber Badge on Monday September 16 2019, @05:59PM (#894730) Journal

      It is powers of 10 true. But it is also true that currencies are ALWAYS integers. Never approximations like floating point.

      Once you recognize it is integers, you can use integer types for much greater efficiency. Integer arithmetic is always EXACT. Even division has an exact quotient and remainder. EXACT. No fuzzyness, ambiguity or imprecision. All currency values (within range) are exactly representable as integer. Conversion to and from Base 10 for printing and parsing is also EXACT. So for Five Dollars you would use an integer of 500.

      --
      The lower I set my standards the more accomplishments I have.