You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Oct 10, 2019. It is now read-only.
It's not like Number doesn't throw in other cases (Number(Symbol()), Number({valueOf: function() { throw Error(); }}))...
Is it because of the inherently-imprecise nature of Number? And the largely-inherently-precise nature of BigInt? (Although given 5n / 2n === 2n, BigInt isn't always precise...)
#132 and #15 touched on this, but I don't think quite addressed it. Apologies in advance if I've missed it or am being dense, as seems likely.
(To be clear, I'm not saying it should throw on all "unsafe" integers, Number(2n**53n + 2n) should continue to work. Just asking why it doesn't throw when precision loss would occur, like BigInt does.)
The text was updated successfully, but these errors were encountered:
There were some important use cases to have an explicit rounding operation, so the Number constructor does that. We debated this question back and forth in various issues on this repository.
Okay, thanks. The inconsistency just tripped me up trying to explain BigInt, hence my (probably sophomoric) attempts to explain above with the "nature" thing. :-) I don't see a discussion of using Number vs. a separate rounding function in the issues, but really that would just be for my curiousity...
BigInt
throws when given a number it can't represent precisely:Why does
Number
not throw when given a BigInt it can't represent precisely?It's not like
Number
doesn't throw in other cases (Number(Symbol())
,Number({valueOf: function() { throw Error(); }})
)...Is it because of the inherently-imprecise nature of Number? And the largely-inherently-precise nature of BigInt? (Although given
5n / 2n === 2n
, BigInt isn't always precise...)#132 and #15 touched on this, but I don't think quite addressed it. Apologies in advance if I've missed it or am being dense, as seems likely.
(To be clear, I'm not saying it should throw on all "unsafe" integers,
Number(2n**53n + 2n)
should continue to work. Just asking why it doesn't throw when precision loss would occur, likeBigInt
does.)The text was updated successfully, but these errors were encountered: