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

Feature request: isNegativeZero #211

Open
innermatrix opened this issue Oct 10, 2024 · 2 comments
Open

Feature request: isNegativeZero #211

innermatrix opened this issue Oct 10, 2024 · 2 comments

Comments

@innermatrix
Copy link

innermatrix commented Oct 10, 2024

function negativeZero(val: unknown): val is 0 {
  return is.number(val) && val === 0 && 1 / val === -Infinity;
}

(Type-level typescript doesn't differentiate between +0 and -0; JS runtime does, if you look closely enough.)

@sindresorhus
Copy link
Owner

Object.is(value, -0) is the easiest way to do. Not sure it's worth adding here as you should almost never have to care about -0 in practice.

@innermatrix
Copy link
Author

Didn't think of that! Tyvm.

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

No branches or pull requests

2 participants