Skip to content

Test if BigInt instance is a finite number#34

Open
omrilotan wants to merge 5 commits into
jonschlinkert:masterfrom
omrilotan:bigint
Open

Test if BigInt instance is a finite number#34
omrilotan wants to merge 5 commits into
jonschlinkert:masterfrom
omrilotan:bigint

Conversation

@omrilotan
Copy link
Copy Markdown

@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

Comment thread index.js
return finite(+num);
}
if (typeof num === 'bigint') {
return finite(Number(num))
Copy link
Copy Markdown

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
Copy Markdown
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
Copy Markdown

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
Copy Markdown

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
Copy Markdown
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