Unofficial Hacker News companion — get notified on comment replies, and more.

Beating Floating Point at Its Own Game: Posit Arithmetic [pdf] (opens external site)

101 points by xenophonf 3 days ago | www.johngustafson.net | 34 comments on HN | Vote on HN (opens Hacker News) |

View full thread · View on Hacker News

Comment thread (4)

  1. Funny thing about spreadsheets is that, if you want to be Excel-compatible, IEEE 754 isn't sufficient. Excel worries a lot about making floating point numbers feel like real numbers to non computer scientists, to the extent that it sacrifices precision to achieve the property that the digits you type might by truncated, but they'll never be rounded to a non-zero digit. And many Excel features work on numbers as displayed, rather than the underlying bytes. Numeric identity isn't bit-equivalence, in Excel (e.g., 0.3 == 0.1 + 0.2). And order isn't even transitive, for some applications (like filters).

    It's very easy to make a spreadsheet that adds binary64 numbers faster than Excel.

    Replies (2)
    1. IEEE 754 isn't sufficient. Excel worries a lot about making floating point numbers feel like real numbers to non computer scientists

      William Kahan, father of IEEE 754, wrote about that: https://people.eecs.berkeley.edu/~wkahan/Mind1ess.pdf

      > And many Excel features work on numbers as displayed, rather than the underlying bytes.

      I think that’s a configuration flag

      Replies (1)
      1. Very interesting, I am doing a review of the types right now so I will read that (and the fat document).
    2. Yes. Some programming languages (raku) allow for 0.1+0.2==0.3 (in that case Rats [or FatRats] are the default for decimal literals). Since Omasheet is built on Polars, I use their Decimal38 type for decimals, but conscious that that does not make 0.1+0.2=0.3, there is also a Fraction type with quotient literals and exact math for rational numbers.

      Unlike Excel, Omasheet is kind of aimed at folk who know and care about numeric types. It has 6 base numeric types Integer(1), Fraction(1/1), Decimal(1.0), Float(1e0), Scientific(1e0(00)) and Complex(1+0i) to cover ℤ, ℚ, ℝ and ℂ conceptually [with basic uncertainty to handle CODATA 2022]. And, like Raku, operations between unlike operands go to the more infectious type - so sin(x) is always irrational (Float or Complex).

      So this, necessarily, is a forced compromise between helping a wide number of math/ science/ data/ education centric users with a sensible set of strict types and having an eye to the Excel level of usability since in the main most users of a spreadsheet are just going to be chucking numbers in and expect it to work.

      I started with Rust BigRat for Fraction, but I couldn't work out a way to line it up with the .parquet file format. Since the goal was to cover all kinds of arithmetic examples including "how many atoms in the universe" and "what is a Googol (100*100)" as well as proper fractions and ℚ without rounding. This works fine atm with symbolic num/den representation (stored as Parquet Struct of Strings. You need to cast into one of the other types to get the Polars engine speed of course, so this is mainly for extreme edge cases and purity.