josdejong/mathjs

Cannot add BigNumber to a `number` matrix

Open

#3,612 opened on 2025年12月16日

GitHub で見る
 (1 comment) (0 reactions) (0 assignees)JavaScript (13,832 stars) (1,298 forks)batch import
bughelp wanted

説明

Describe the bug At least as of version 15.1, mathjs refuses to add a BigNumber scalar to a matrix that has been typed as containing number entries.

To Reproduce In the mathjs.org REPL:

> matrix([[1, 2]], 'dense', 'number') + bignumber(3)
   Error: Cannot convert 3 to number

Expected behavior I would expect the above operation to produce a 1×2 dense matrix with entries number(1) + bignumber(3) and number(2) + bignumber(3), respectively, which would be [[bigumber(4), bignumber(5)]] by current mathjs promotion rules. Ideally, the resulting matrix would be typed as containing bignumber entries, but that might have to wait for something like the nanomath engine that records return types (unless for now we just assume that since the input was homogeneous in type the output will be, too, and test just one entry. But that kind of assumption could break down for bigint divided by bigint, say -- the result might be a mix of bigints and fractions...

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