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 PiMuNu on Monday September 16 2019, @02:32PM (28 children)

    by PiMuNu (3823) on Monday September 16 2019, @02:32PM (#894604)

    thanks

    Starting Score:    1  point
    Karma-Bonus Modifier   +1  

    Total Score:   2  
  • (Score: 2) by FatPhil on Monday September 16 2019, @04:16PM (27 children)

    by FatPhil (863) <{pc-soylent} {at} {asdf.fi}> on Monday September 16 2019, @04:16PM (#894665) Homepage
    Meh. The author started out by comparing COBOL with Java, which proved to me that she knew very little about floating point arithmetic, or at least how dangerous Java is for floating point arithmetic. Either that, or she did know that, and deliberately chose one of the worst languages possible for the comparison, which is little more than setting light to a straw man. Friends don't let friends do Java.
    --
    Great minds discuss ideas; average minds discuss events; small minds discuss people; the smallest discuss themselves
    • (Score: 0) by Anonymous Coward on Monday September 16 2019, @04:56PM (2 children)

      by Anonymous Coward on Monday September 16 2019, @04:56PM (#894679)

      Friends don't let friends do Java.

      But especially don't let friends use Java that can't figure out how to program using Java.

      • (Score: 3, Insightful) by DannyB on Monday September 16 2019, @06:19PM (1 child)

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

        It's pretty amazing how Java has come to be one of the top languages for years running now. Somebody must know something that the rest of the industry doesn't know. Must be nice to be so smart and unappreciated.

        --
        Young people won't believe you if you say you used to get Netflix by US Postal Mail.
        • (Score: 0) by Anonymous Coward on Tuesday September 17 2019, @01:50AM

          by Anonymous Coward on Tuesday September 17 2019, @01:50AM (#894948)

          You mean the same industry that uses mass surveillance, creates web 2.0 abominations, and is responsible for disservices like Facebook? That wise, wise industry which is known for its high-quality code, good decision-making, and long-term thinking? The very same industry that needs to be nuked from orbit? Yeah, it would take a real genius to be smarter than the ridiculous MBA losers who have almost complete control.

    • (Score: 2) by PiMuNu on Monday September 16 2019, @05:02PM (1 child)

      by PiMuNu (3823) on Monday September 16 2019, @05:02PM (#894685)

      Fair enough. I don't know much about java, replaced java in my head with C. I am a scientific programmer who deals with floating point precision issues routinely; I had never really thought about alternatives to floating point arithmetic so I found it interesting.

      • (Score: 2) by kazzie on Monday September 16 2019, @05:30PM

        by kazzie (5309) Subscriber Badge on Monday September 16 2019, @05:30PM (#894704)

        By coincidence I was looking at issues of fixed point and floating point at work today, when contemplating square root algorithms for an FPGA. As a result I found the article both interesting and timely.

    • (Score: 1) by nitehawk214 on Monday September 16 2019, @05:16PM (16 children)

      by nitehawk214 (1304) on Monday September 16 2019, @05:16PM (#894696)

      You do realize that C has floating point datatypes and suffer the same flaws, right? And that no precise calculations should use them, right?

      --
      "Don't you ever miss the days when you used to be nostalgic?" -Loiosh
      • (Score: 2) by FatPhil on Monday September 16 2019, @05:52PM (13 children)

        by FatPhil (863) <{pc-soylent} {at} {asdf.fi}> on Monday September 16 2019, @05:52PM (#894727) Homepage
        C's floating points *absolutely DO NOT* have the same flaws as Java.

        Have you ever read any Kahan?

        So if the penaly fees were 300*1.27^(17/365), how much *exactly* do I owe?
        No, exactly, not that approximation.
        --
        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:17PM (3 children)

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

          C's floating points *absolutely DO NOT* have the same flaws as Java.

          Unrelated to financial calculations. Please elaborate on that. I tend to think of standardized FP implementations are giving the same results.

          I kind of thought that the whole point of IEEE standards were binary interchangeable formats, and reproducible results. Something sadly lacking once long ago when ever language, indeed every implementation of every compiler had its own weird FP implementation.

          Thanks.

          --
          Young people won't believe you if you say you used to get Netflix by US Postal Mail.
          • (Score: 2) by FatPhil on Tuesday September 17 2019, @07:47AM (2 children)

            by FatPhil (863) <{pc-soylent} {at} {asdf.fi}> on Tuesday September 17 2019, @07:47AM (#895062) Homepage
            See my link to Kahan's JAVAHurt.pdf elsethread.
            --
            Great minds discuss ideas; average minds discuss events; small minds discuss people; the smallest discuss themselves
            • (Score: 2) by DannyB on Tuesday September 17 2019, @02:12PM (1 child)

              by DannyB (5839) Subscriber Badge on Tuesday September 17 2019, @02:12PM (#895145) Journal

              Can you kindly point me to that link please?

              --
              Young people won't believe you if you say you used to get Netflix by US Postal Mail.
              • (Score: 2) by DannyB on Tuesday September 17 2019, @02:12PM

                by DannyB (5839) Subscriber Badge on Tuesday September 17 2019, @02:12PM (#895146) Journal

                Nevermind, I believe I found it.

                --
                Young people won't believe you if you say you used to get Netflix by US Postal Mail.
        • (Score: 2) by DannyB on Monday September 16 2019, @06:44PM (8 children)

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

          Have you ever read any Kahan?

          Obviously not. Can you elaborate on what Kahan is?

          Googling for Java vs C floating point. I find that Java FP, depends on platform implementation, and a runtime option. Based on these, Java may do intermediate> arithmetic of 32-bit floats, using higher precision before converting back to 32-bit floats. If C / C++ don't do this, that could account for some discrepancy.

          I don't find a whole lot of relevant anything that pops up in Google. So I'm sincerely interested in what Java gets wrong in floating point.

          I do notice a number of examples of values that are not exactly representable in floating point. The famous 0.1 is but one of many examples. In fact, I suspect there are a huge number of exact decimal numbers not exactly representable in binary, and vice versa.

          --
          Young people won't believe you if you say you used to get Netflix by US Postal Mail.
          • (Score: 2, Informative) by Anonymous Coward on Monday September 16 2019, @07:25PM (1 child)

            by Anonymous Coward on Monday September 16 2019, @07:25PM (#894772)

            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

              by DannyB (5839) Subscriber Badge on Monday September 16 2019, @08:02PM (#894786) Journal

              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.

              So there are a lot of denominators that are available in base ten but not base two.

              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.

              --
              Young people won't believe you if you say you used to get Netflix by US Postal Mail.
          • (Score: 3, Informative) by FatPhil on Tuesday September 17 2019, @07:20AM (5 children)

            by FatPhil (863) <{pc-soylent} {at} {asdf.fi}> on Tuesday September 17 2019, @07:20AM (#895054) Homepage

            Kahan is one of the guys who wrote the IEEE754 floating point standards. Hasn't been a research academic for a long time, but over the decades has published a whole bunch of reports on what can go wrong with FP, including at the language-implementation level, such as How JAVA's Floating-Point Hurts Everyone Everywhere [berkeley.edu] (PDF file) whose title should be self-explanatory.

            --
            Great minds discuss ideas; average minds discuss events; small minds discuss people; the smallest discuss themselves
            • (Score: 2) by DannyB on Tuesday September 17 2019, @02:23PM (4 children)

              by DannyB (5839) Subscriber Badge on Tuesday September 17 2019, @02:23PM (#895151) Journal

              That is interesting.

              It is from 1998, over twenty years ago. Java has changed a lot -- but I don't know how much in relation to this topic.

              There are a few rebuttals I could make -- but, I don't use floating point much in Java. But I've never had a problem with it.

              Since I mostly work with BigDecimal (which is really an unlimited precision integer underneath), I don't have the inexactness of floating point approximations of money values.

              --
              Young people won't believe you if you say you used to get Netflix by US Postal Mail.
              • (Score: 2) by FatPhil on Tuesday September 17 2019, @02:51PM (3 children)

                by FatPhil (863) <{pc-soylent} {at} {asdf.fi}> on Tuesday September 17 2019, @02:51PM (#895160) Homepage
                The complaints are mostly from an HPC persepective, big simulations and modelling, with lots of feedback and opportunities for seemingly trivial inaccuracies can have larger cascading consequences. Finance is abacus work compared to that.

                Having a specific type for currency values is ideal (as long as you can trust the implementer of that black box). It can also help with dimensional correctness too, if you have strict typing.
                --
                Great minds discuss ideas; average minds discuss events; small minds discuss people; the smallest discuss themselves
                • (Score: 3, Interesting) by DannyB on Tuesday September 17 2019, @03:32PM (2 children)

                  by DannyB (5839) Subscriber Badge on Tuesday September 17 2019, @03:32PM (#895191) Journal

                  Microsoft, amusingly, has a type for currency. It is basically your standard 2s compliment 64 bit integer with an implied decimal point four places from the right. So it counts in hundredths or a cent, or ten-thousandths of a dollar -- or whatever unit of currency in use.

                  I would like to see more languages that can attach dimensional correctness to scalar values, which in turn can be carried into more complex types such as rational values, complex numbers, etc. It would be a compile time error to have incorrect dimensions.

                  But when I muse about higher level and more abstract languages, I am often taken to task for it because programming should always be only about working at the bits and bytes and cpu cycles.

                  --
                  Young people won't believe you if you say you used to get Netflix by US Postal Mail.
                  • (Score: 2) by FatPhil on Wednesday September 18 2019, @08:19AM (1 child)

                    by FatPhil (863) <{pc-soylent} {at} {asdf.fi}> on Wednesday September 18 2019, @08:19AM (#895536) Homepage
                    Never knew about the MS centi-cents - interesting. That has the side effect of still forcing the programmer to do with the centi-cents they don't want to propagate to the outside world (invoice/etc.). I don't like the implication that every single step of a financial calculation will be performed in this type, because the errors would accumulate at a terifying rate compared with how quickly they would if you were performing the calculations in FP, unless everything you are dealing with was multi-billion. I fear this might be a half-baked idea. Inside the black box, always use the best tool for the job. There really needs to be 2 currency types - currency-for-userspace and currency-for-calculations - where the user should never see or use the latter.
                    --
                    Great minds discuss ideas; average minds discuss events; small minds discuss people; the smallest discuss themselves
                    • (Score: 2) by DannyB on Wednesday September 18 2019, @01:58PM

                      by DannyB (5839) Subscriber Badge on Wednesday September 18 2019, @01:58PM (#895640) Journal

                      Microsoft has had its currency type since at least the 1990's. It is in all their languages, as far as I know, but started in VB, I think. At the time it probably seemed like a good idea. And it probably stopped many programmers from using floating point instead.

                      --
                      Young people won't believe you if you say you used to get Netflix by US Postal Mail.
      • (Score: 3, Insightful) by iWantToKeepAnon on Tuesday September 17 2019, @02:36PM (1 child)

        by iWantToKeepAnon (686) Subscriber Badge on Tuesday September 17 2019, @02:36PM (#895156) Homepage Journal

        "Don't you ever miss the days when you used to be nostalgic?" -Loiosh

        Nostalgia isn't what it used to be. :/

        --
        "Happy families are all alike; every unhappy family is unhappy in its own way." -- Anna Karenina by Leo Tolstoy
        • (Score: 1) by nitehawk214 on Wednesday September 18 2019, @02:27PM

          by nitehawk214 (1304) on Wednesday September 18 2019, @02:27PM (#895657)

          "Happy families are all alike; every unhappy family is unhappy in its own way." -- Anna Karenina by Leo Tolstoy

          Wtf is a happy family? Something that only happens in books? :/

          --
          "Don't you ever miss the days when you used to be nostalgic?" -Loiosh
    • (Score: 5, Informative) by sjames on Monday September 16 2019, @07:22PM (1 child)

      by sjames (2882) on Monday September 16 2019, @07:22PM (#894771) Journal

      The author made a fair point that the industry frequently bills Java as COBOL's natural successor, so it is perfectly fair to compare the two to see why that may not be such a good idea and why it hasn't been all that successful so far.

      TLDR; The choice of Java for comparison was not made in a vacuum. No word of spherical cows.

      • (Score: 2) by FatPhil on Tuesday September 17 2019, @07:13AM

        by FatPhil (863) <{pc-soylent} {at} {asdf.fi}> on Tuesday September 17 2019, @07:13AM (#895049) Homepage
        Fair point, +1. I've mostly ignored Java, as I do more scientific programming than business programming, which emphasises your point - Java clearly has that "business language" aura about it.
        --
        Great minds discuss ideas; average minds discuss events; small minds discuss people; the smallest discuss themselves
    • (Score: 2, Insightful) by Anonymous Coward on Monday September 16 2019, @07:36PM

      by Anonymous Coward on Monday September 16 2019, @07:36PM (#894773)

      I recall my manager's manager pushing towards Java. And then watched two competent software engineers struggle for 8 months with making Java work with simple numbers. The language is a pile of _insert_favorite_expletive_ since day one and has never improved. I cut my teeth on COBOL and despite being overdue for a place at the paliative care center, it can at least work simple arithmetic. New and Shiny is not always Better.
      Do systems need to get updated? Yes. But choose good languages, OSes, tools. Too many people fall for some flashy presentation. That's how we have arrived at the mess the industry has become today.

    • (Score: 1) by cyberthanasis on Wednesday September 18 2019, @07:42AM (1 child)

      by cyberthanasis (5212) on Wednesday September 18 2019, @07:42AM (#895531)

      Not at all. She says that Java is what is usually used to replace Cobol. And she actually gives examples about numerical instability with floats and fixed point reals.
      And she says that Java does have fixed point library, but Cobol has fixed point builtin and it is a compiled language. Therefore it is better when you need millions of transaction per second.

      • (Score: 2) by FatPhil on Wednesday September 18 2019, @08:40AM

        by FatPhil (863) <{pc-soylent} {at} {asdf.fi}> on Wednesday September 18 2019, @08:40AM (#895540) Homepage
        You seem to be reading too much, or too little, into "compiled", "library", and "builtin".
        --
        Great minds discuss ideas; average minds discuss events; small minds discuss people; the smallest discuss themselves