josdejong/mathjs

Cannot add BigNumber to a `number` matrix

Open

#3,612 创建于 2025年12月16日

在 GitHub 查看
 (1 评论) (0 反应) (0 负责人)JavaScript (13,832 star) (1,298 fork)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...

贡献者指南