Daily Shaarli

All links of one day in a single page.

May 25, 2023

Solving the "floating point precision" problem with... floats? - DEV Community

A really innovative way to store exact floating point numbers:

  1. for "safe numbers" (numbers whose value can be expressed precisely in floating point), store them as is
  2. for non-"safe numbers", store two safe numbers as denominator and nominator.

There is a lot of this method comparing to the other alternatives:

  • BigDecimal: a lot faster than arbitrary precision BigDecimal
  • Rational: denom and nom deoesn't blow up to extremely large numbers

And it is also faster and uses less space.