New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Cannot implicitly convert a number with >15 significant digits to BigNumber #1269

Closed
zcohan opened this Issue Oct 3, 2018 · 4 comments

Comments

Projects
None yet
3 participants
@zcohan

zcohan commented Oct 3, 2018

Here's my code:

math.config({number: 'BigNumber', precision: 64})
math.eval('80 / day * 5 days')

I'm expecting the result '400'.

It works fine without configuring with BigNumber, but I do need to use BigNumber on my math object in general, as high precision might be important for the calculation and I don't know the user's expression ahead of time. I've tried BigNumbering parts of the expression, but haven't had any luck.

@josdejong

This comment has been minimized.

Show comment
Hide comment
@josdejong

josdejong Oct 3, 2018

Owner

That's an interesting issue, thanks for reporting. Looks like somewhere in the evaluation a number is introduced (most likely the unit day is represented as a Unit with a value being a number instead of a BigNumber.

Owner

josdejong commented Oct 3, 2018

That's an interesting issue, thanks for reporting. Looks like somewhere in the evaluation a number is introduced (most likely the unit day is represented as a Unit with a value being a number instead of a BigNumber.

@ericman314

This comment has been minimized.

Show comment
Hide comment
@ericman314

ericman314 Oct 4, 2018

Collaborator

This is because of the hard-coded _normalize(1) in divideScalar.js. The 1 needs to be promoted to a BigNumber before being passed to _normalize in order to avoid the error.

I submitted PR #1270 which fixes the bug in this particular case, but I don't know if it's a permanent fix. It seems a little sloppy. I would have rather applied the fix to _normalize itself, but that function doesn't seem to be the source of the bug. There are TODOs in divideScalar.js to move the division into Unit.js, perhaps it's time to do just that?

Collaborator

ericman314 commented Oct 4, 2018

This is because of the hard-coded _normalize(1) in divideScalar.js. The 1 needs to be promoted to a BigNumber before being passed to _normalize in order to avoid the error.

I submitted PR #1270 which fixes the bug in this particular case, but I don't know if it's a permanent fix. It seems a little sloppy. I would have rather applied the fix to _normalize itself, but that function doesn't seem to be the source of the bug. There are TODOs in divideScalar.js to move the division into Unit.js, perhaps it's time to do just that?

@josdejong

This comment has been minimized.

Show comment
Hide comment
@josdejong

josdejong Oct 5, 2018

Owner

This issue has been fixed now in v5.2.0. Thanks again @ericman314 !

Owner

josdejong commented Oct 5, 2018

This issue has been fixed now in v5.2.0. Thanks again @ericman314 !

@zcohan

This comment has been minimized.

Show comment
Hide comment
@zcohan

zcohan Oct 7, 2018

This issue has been fixed now in v5.2.0. Thanks again @ericman314 !

Confirmed fixed on my end too. Thanks @josdejong & @ericman314!

zcohan commented Oct 7, 2018

This issue has been fixed now in v5.2.0. Thanks again @ericman314 !

Confirmed fixed on my end too. Thanks @josdejong & @ericman314!

@zcohan zcohan closed this Oct 7, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment