‹ BackHN Continuity

Thread

More floating point alternatives

53 points · 51 comments · vismit2000

  1. AlotOfReading · · focus · HN ↗
    Usually, if you know enough about your algorithms to select an appropriate float alternative, you also know enough to fix your float code and that's what you should actually do.

    That said, some of these aren't alternatives. Symbolic computation is a different thing entirely. Interval arithmetic can be built atop floats (e.g. IEEE-1788) and has its own zoo of unintuitive behaviors. BCD is better called a historical artifact than an alternative these days.

    It's really just rationals and decimal floats in this list, which probably don't solve the issues you have if you're considering float alternatives.

    1. TZubiri · · focus · HN ↗
      You can't "fix" floating point code if you are looking for deterministic answers. You just have to use other data types to handle money or complex mathematical operations like 0.2+0.1, no ifs and buts.
      1. messe · · focus · HN ↗
        Floating point is deterministic, what are you talking about?

        > You just have to use other data types to handle money or complex mathematical operations like 0.2+0.1

        Such as... decimal floating point.

        1. timschmidt · · focus · HN ↗
          > Floating point is deterministic, what are you talking about?

          Order of operations can change a result, for example. I suspect you mean that the algorithm never changes. While op means that mathematical operations which most folks would expect to be reliable are not.

          1. messe · · focus · HN ↗
            They're not associative, sure. But that's a very far cry from claiming they're non-deterministic.
            1. timschmidt · · focus · HN ↗
              There are enough problems for a 44 page paper titled "What Every Computer Scientist Should Know About Floating-Point Arithmetic"[1] I don't quibble on the language because I know what people mean.

              Most folks won't encounter most of the issues, generally. But expose your code to a large enough dataset, or be like me and write a CAD/CAM system with motion control and experience most of them.

              That's why I wrote hyperreal[2]

              1: <a href="https:&#x2F;&#x2F;www.cs.tufts.edu&#x2F;cs&#x2F;40&#x2F;docs&#x2F;WhatEveryComputerScientistShouldKnowAboutFloatingPointArithmetic.pdf" rel="nofollow">https:&#x2F;&#x2F;www.cs.tufts.edu&#x2F;cs&#x2F;40&#x2F;docs&#x2F;WhatEveryComputerScienti...

              2: <a href="https:&#x2F;&#x2F;github.com&#x2F;timschmidt&#x2F;hyperreal" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;timschmidt&#x2F;hyperreal

              1. dspillett · · focus · HN ↗
                That (no doubt excellent, but) technical PDF is overselling the problem somewhat, when what every dev needs to know is better represented by a friendlier summary like <a href="https:&#x2F;&#x2F;floating-point-gui.de&#x2F;" rel="nofollow">https:&#x2F;&#x2F;floating-point-gui.de&#x2F;
                1. timschmidt · · focus · HN ↗
                  That&#x27;s a great resource as well. Targeted at developers, rather than computer scientists. Same observations, different target audiences and expectations. You&#x27;re probably right that the more practical reference targeted at developers is more useful here. My references are full of the academic papers because of my CAD work.
                  1. dspillett · · focus · HN ↗
                    &gt; Targeted at developers

                    Sorry, yes, I probably should have worded that in a way that made the distinction more obvious.

Open on Hacker News to reply ↗

Unofficial Hacker News client; not affiliated with Y Combinator.