‹ 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. SkiFire13 · · focus · HN ↗
        > deterministic answers

        > 0.2+0.1

        0.2+0.1 with floating point numbers _is_ deterministic, as you'll always get the same answer.

        I suspect you might instead mean exact calculations/answers (in the example above, neither 0.1, 0.2 nor 0.3 have exact representations using floating point numbers).

        And just to be clear, there are non-determinism-like issues with floating point numbers, but those are much rarer/niche and _can_ be fixed. For example parallel summation depends on the order the summation was made, so non-determinism in the parallel implementation ripples through the summation result. Some non-basic operations (e.g. trigonometric operations) have platform dependent implementations with different roundings, so you might experience different result based on the platform you're on.

Open on Hacker News to reply ↗

Unofficial Hacker News client; not affiliated with Y Combinator.