josdejong/mathjs

Incompatibility between `number: bigint` and high-precision floating point arithmetic

オープン

#3,539 opened on 2025/09/25

 (3 件のコメント) (0 件のリアクション) (0 人の担当者)JavaScript (1,314 件のフォーク)batch import
bughelp wanted

Repository metrics

Stars
 (15,065 個のスター)
PR merge metrics
 (PR metrics pending)

説明

with math.js 14.6.0

math.config({
  number: "bigint", 
  precision: 998,
  relTol: 1e-320,
  absTol: 1e-323,
  numberFallback: "BigNumber"
});

outch, a part of the code doing stuff like :

  • math.log10( 0n ) (which before was containing bignumbers) returns errors now "i.toNumber is not a function"
  • math.log( 123n ) returns now 4.812184355372417 , before it was returning a bignumber of 998 digits
  • floor(log10(( 1n ))) returns now "Number of decimals in function round must be an integer from 0 to 15 inclusive"

I was parsing big integers as bignumber to return long primes and now I get messages like this "Cannot mix BigInt and other types, use explicit conversions"

the price to pay in code update seems very high , and all calculations based on logarithms no longer return the configuration's precision. every constant are now limited to few digits math.pi = 3.141592653589793.

Originally posted by @nycos62 in https://github.com/josdejong/mathjs/discussions/3533#discussioncomment-14504003

These are all bugs; it should be possible to conveniently perform high-precision floating-point arithmetic when (perhaps especially when) numbers default to bigints.

コントリビューターガイド