Skip to content

Fix adding a BigNumber scalar to a number-datatype matrix#3677

Open
apoorva-01 wants to merge 1 commit into
josdejong:developfrom
apoorva-01:fix-3612
Open

Fix adding a BigNumber scalar to a number-datatype matrix#3677
apoorva-01 wants to merge 1 commit into
josdejong:developfrom
apoorva-01:fix-3612

Conversation

@apoorva-01

Copy link
Copy Markdown

add(matrix([[1, 2]], 'dense', 'number'), bignumber(3)) threw Cannot convert 3 to number instead of returning [[4, 5]] as BigNumbers. Thanks for the pointer to matAlgo14xDs.

When a matrix has a declared datatype, the dense scalar path converts the scalar into that datatype first. BigNumber -> number is lossy so it throws, instead of promoting like mathjs normally would. Fix takes that fast path only when the scalar actually converts, otherwise it falls back to the generic per-element callback (same path a number matrix with no declared datatype already uses). Result is [[bignumber(4), bignumber(5)]], datatype dropped to undefined.

One call for you: I kept this to the reported dense case. The sparse path (matAlgo11xS0s) and the other matrix-scalar algos have the same force-conversion and throw the same way (checked sparse). Happy to fix them all here if you'd rather one sweep, but left it contained given your note that there are probably more spots. Some overlap with #3607 too, which rewrites this file for other reasons.

closes #3612

matAlgo14xDs forced the scalar into the matrix's datatype, so a BigNumber
plus a `number` matrix threw instead of promoting. Take that fast path only
when the scalar converts, otherwise fall back to the generic callback.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot add BigNumber to a number matrix

1 participant