Skip to content

Cannot add BigNumber to a number matrix #3612

@gwhitney

Description

@gwhitney

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...

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions