is icon indicating copy to clipboard operation
is copied to clipboard

Feature request: isNegativeZero

Open innermatrix opened this issue 1 year ago • 2 comments

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

innermatrix avatar Oct 10 '24 15:10 innermatrix

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.

sindresorhus avatar Oct 10 '24 15:10 sindresorhus

Didn't think of that! Tyvm.

innermatrix avatar Oct 10 '24 20:10 innermatrix