josdejong/mathjs

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

Open

#3.539 aberto em 25 de set. de 2025

Ver no GitHub
 (3 comments) (0 reactions) (0 assignees)JavaScript (1.298 forks)batch import
bughelp wanted

Métricas do repositório

Stars
 (13.832 stars)
Métricas de merge de PR
 (Nenhuma PRs mesclada em 30d)

Description

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.

Guia do colaborador