Skip to content

Should BigNumber.from accept MAX_SAFE_INTEGER? #1582

Answered by ricmoo
fvictorio asked this question in Q&A
Discussion options

You must be logged in to vote

This is intentional to better detect errors near the boundary. I have seen a lot of instances where people use numbers inappropriately, so I error on the side of caution.

This obviously cannot help in all cases (since IEEE 754 could have corrupted the value anywhere along the way), but consider:

> Number.MAX_SAFE_INTEGER + 2 - 1 === Number.MAX_SAFE_INTEGER
true

// This would mean with the above change this would succeed, when I want it to fail:
// BigNumber.from(Number.MAX_SAFE_INTEGER + 2 - 1)

I would ideally lower the threshold a lot further, but there is always going to be cases of undetectable corruption, so this seemed like a fair compromise...

Does that make sense?

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@fvictorio
Comment options

Answer selected by fvictorio
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants