menu

no-compare-neg-zero

Disallow comparisons with negative zero

Equality and ordering comparisons produce the same result for negative and positive zero, so a comparison against negative zero cannot test its sign. Instead, you SHOULD compare with zero and call .isSignNegative() when the sign matters.

Reported

1function isNegativeZero(value: float64): boolean {2    return value === -0.0;3}

Accepted

1function isNegativeZero(value: float64): boolean {2    return value === 0.0 && value.isSignNegative();3}