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

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

102 points by xenophonf 4 days ago | www.johngustafson.net | 38 comments on HN | Vote on HN (opens Hacker News) |

View full thread · View on Hacker News

Comment thread (1)

  1. 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.