josdejong / mathjs

An extensive math library for JavaScript and Node.js
https://mathjs.org
Apache License 2.0
14.44k stars 1.24k forks source link

BigNumber comparison #2949

Closed shmsula closed 1 year ago

shmsula commented 1 year ago

Tried to compare two big numbers (1000000000000), however only last version works.

image

Is it correct behavior?

josdejong commented 1 year ago

The equality operators use an epsilon to compare numbers, which is 1e-12 by default. You will want to use a smaller epsilon.

See docs: https://mathjs.org/docs/datatypes/bignumbers.html#usage

josdejong commented 1 year ago

See also #2608, discussing the introduction of a separate epsilon for bignumbers to prevent the issue you're running into.