1. 2

    Whoever attempts floating-point calculation with JavaScript is, of course, in a state of sin.

    John von Neumann, probably.

    1. 1

      What language should one use for floating point calculations?

      1. 6

        TCL, of course, because EIAS!

        1. 3

          In most languages there are libraries to deal with precise numbers. For example, you can use Decimal in Python. https://docs.python.org/3/library/decimal.html

          But it may not be as fast or have other inconveniences (for example, defining explicitly the precision)

          1. 2

            There are some good examples in the list @HugoDaniel posted in this thread.

            Here’s something interesting for JS: http://mikemcl.github.io/decimal.js/

            1. 1

              If you want it to work correctly, then probably SPARK, C w/ tooling, or Gappa w/ language of your choosing. If performance isn’t an issue, there’s a pile of languages with arbitrary-precision arithmetic plus libraries for those without it. I’d say that’s the options.

              Meanwhile, there’s work in formal methods on Exact-Real Arithmetic that could give us new options later. There was an uptick in it in 2018. I’m keeping an distant eye on it.

          1. 1

            The module sh is a fantastic tool for these kind of scripts. https://github.com/amoffat/sh