sindresorhus / is

Type check values
MIT License
1.68k stars 109 forks source link

Feature request: isNegativeZero #211

Open innermatrix opened 1 month ago

innermatrix commented 1 month ago
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 commented 1 month ago

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 commented 1 month ago

Didn't think of that! Tyvm.