josdejong / josdejong/mathjs

Cannot add BigNumber to a `number` matrix

Open
#3,612 1 comment 0 reactions 0 assignees View on GitHub
bug help wanted
Dominant language
JavaScript
Stars
15.1k
Forks
1.3k
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.