• zerofk@lemm.ee
    link
    fedilink
    arrow-up
    5
    arrow-down
    1
    ·
    1 day ago

    There is a paper titled “What Every Computer Scientist Should Know About Floating-Point Arithmetic” by David Goldberg. It’s a bit theoretical, but IMO it’s a must-read for any programmer doing more than the occasional floating point calculation. It goes beyond just limited precision and rounding errors.

  • call_me_xale@lemmy.zip
    link
    fedilink
    arrow-up
    10
    ·
    2 days ago

    More people need to learn to use Rational types. A pretty large majority of the numbers that people care about in real life can easily be represented by a ratio of integers, and they allow math with perfect precision.

    • Quetzalcutlass@lemmy.world
      link
      fedilink
      English
      arrow-up
      3
      ·
      1 day ago

      Someone posted this article a while back that goes into more detail on some alternatives, as well as contains one of the best and most intuitive explanations of floating point that I’ve ever read.

    • boonhet@lemm.ee
      link
      fedilink
      arrow-up
      7
      ·
      2 days ago

      Or just BigDecimal or an equivalent if rational types aren’t easy to use in your language (e.g if you’d have to literally enter the denominator and numerator).