Stdlib Gives Identical JavaScript Math Results Across Browsers and Node.js

JavaScript's built-in Math object leaves room for engines to return slightly different bits for the same input, so results can vary by engine and version. Libraries such as jStat, math.js, and decimal.js exist to fill gaps in numerical computing. The stdlib project instead implements its own functions from the specification rather than calling the engine's maths library. In tests, Math.tan(7) differed in the last digit across three browsers, while stdlib's version returned one identical value. Across 4,053 test cases for erf and ldexp, outputs were hashed and compared, and all runs matched except for one difference in how engines stored "not a number" on a single input.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)
Log in to join the discussion and vote.
Log in