Security News
New Proposed CISA Mandate Would Require Critical Infrastructure to Report Ransom Payments Within 24 Hours
CISA has proposed a set of new rules that would require critical infrastructure to report cyber incidents and ransom payments.
is-negative-zero
Advanced tools
Is this value negative zero? === will lie to you
Weekly downloads
Package description
The is-negative-zero npm package is a utility that provides a simple function to check if a given number is -0. In JavaScript, -0 and +0 are considered distinct values (due to IEEE 754 floating point), and this package helps in identifying if a number is specifically -0.
Check if a number is -0
This feature allows you to check if a given number is exactly -0. It returns true if the number is -0, and false otherwise. This can be particularly useful in mathematical computations and graphics programming where the distinction between -0 and +0 can have implications.
const isNegativeZero = require('is-negative-zero');
console.log(isNegativeZero(-0)); // true
console.log(isNegativeZero(0)); // false
console.log(isNegativeZero(-1)); // false
Similar to is-negative-zero, is-zero is a utility for checking if a number is 0. However, it does not distinguish between -0 and +0, making it less specific for cases where the sign of zero matters.
While not specifically designed for checking -0, lodash's isEqual function can accurately compare -0 and +0, among many other complex equality checks. It's more versatile but also much larger and more complex than is-negative-zero, which is focused solely on the -0 check.
Readme
Is this value negative zero? === will lie to you.
var isNegativeZero = require('is-negative-zero');
var assert = require('assert');
assert.notOk(isNegativeZero(undefined));
assert.notOk(isNegativeZero(null));
assert.notOk(isNegativeZero(false));
assert.notOk(isNegativeZero(true));
assert.notOk(isNegativeZero(0));
assert.notOk(isNegativeZero(42));
assert.notOk(isNegativeZero(Infinity));
assert.notOk(isNegativeZero(-Infinity));
assert.notOk(isNegativeZero(NaN));
assert.notOk(isNegativeZero('foo'));
assert.notOk(isNegativeZero(function () {}));
assert.notOk(isNegativeZero([]));
assert.notOk(isNegativeZero({}));
assert.ok(isNegativeZero(-0));
Simply clone the repo, npm install
, and run npm test
FAQs
Is this value negative zero? === will lie to you
The npm package is-negative-zero receives a total of 23,242,832 weekly downloads. As such, is-negative-zero popularity was classified as popular.
We found that is-negative-zero demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISA has proposed a set of new rules that would require critical infrastructure to report cyber incidents and ransom payments.
Security News
Redis is no longer OSS, breaking its explicit commitment to remain under the BSD 3-Clause License forever. This has angered contributors who are now working to fork the software.
Product
Socket AI now enables 'AI detected potential malware' alerts by default, ensuring users benefit from AI-powered state-of-the-art malware detection without needing to opt-in.