-
-
Notifications
You must be signed in to change notification settings - Fork 49
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
Test if BigInt instance is a finite number #34
base: master
Are you sure you want to change the base?
Conversation
return finite(+num); | ||
} | ||
if (typeof num === 'bigint') { | ||
return finite(Number(num)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why convert? why not true
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the "finite" function (Number.isFinite) will check whether the output is a value that can be represented by a Javascript number. The return value will be a Boolean.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sorry, I wasn't clear. I meant that BigInt
s could always be considered as "valid numerical values" (as in math), not necessarily "all BigInt
s are valid Number
s, because they never coerce to NaN
"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait, now that I think about it, that should be a separate function named isNumeric
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, probably.
Anyway I don't think this changeset is getting merged (almost three years old 🍰)
BigInt can represent a value that can be represented by a number or larger.
This now checks if it is representing a value that can be represented by a Javascript number.
Disclosure: There's a performance hit for non-string or numbers. Others are obviously not affected