Unofficial Hacker News client - receive Push Notifications on replies.

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

100 points by xenophonf 1 day ago | www.johngustafson.net | 33 comments on HN | Vote on HN (opens Hacker News)

View full thread · View on Hacker News

Comment thread (7)

  1. Having witnessed the acceleration and adoption of IEEE754 close up (Weitek in the 80s), it is easy to underestimate the level of hardware tuning tricks baked into and developed around that standard.

    I have made a spreadsheet app in Rust with exact and fast arithmetic, centered on Apache Arrow and Polars, so Integer (i64) and Float (f64) are joined by Decimal[n] (.parquet Decimal38) and Fraction(num/dec).

    After considering some alternatives for Fraction, including BigRat and maybe interval arithmetic the current pick is symbolic handling of num/dec stored as .parquet Strings. Why? Well the other three types are fast, so it seems OK to have a slow but sure “back stop”.

    It works well for Googol ranges of arithmetic and knows that 1/7+4/7 is 5/7. This seems good for teaching purposes and scratching the exactness itch.

    Anyway, I’m open to adding Posit provided there’s a Rust crate (fast-posit.rs?) and a way to shoe horn them into parquet. Please raise an issue over at https://omasheet.org repo if this is of interest.

    Replies (2)
    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.

    2. I'm the maintainer of fast-posit. It is not "feature complete" in the sense that it doesn't implement all those elementary functions prescribed by the standard, with 100% correct rounding (far beyond my powers :)). It does impl the four basic operations, sqrt, conversions between it and all fundamental Rust numeric types, comparisons, all quire operations (add, sub, dot product): everything correctly rounded, and tested exhaustively or with proptest. It also supports "bounded-posits" (one more parameter you tweak to make sure your type covers your expected domain accurately).

      You're welcome to give it a try! https://github.com/andrepd/posit-rust/

      I'm not sure how relevant it is to you, since you require exact arithmetic! In fact I'm not sure how you even use floats at all.

      Replies (1)
      1. thanks! I'll take a look ... one of the scary/fun things about LLM era development is we could just make a posit spreadsheet ... the question is "why" ;-)