Skip to content
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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

omrilotan
Copy link

@omrilotan omrilotan commented Jan 24, 2022

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

return finite(+num);
}
if (typeof num === 'bigint') {
return finite(Number(num))
Copy link

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?

Copy link
Author

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.

Copy link

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 BigInts could always be considered as "valid numerical values" (as in math), not necessarily "all BigInts are valid Numbers, because they never coerce to NaN"

Copy link

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

Copy link
Author

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 🍰)

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.

2 participants