never return -0

This commit is contained in:
Cory LaViska
2023-01-10 16:14:30 -05:00
parent 68ed69292c
commit 0df27cf730

View File

@@ -1,10 +1,14 @@
/** Ensures a number stays within a minimum and maximum value */
export function clamp(value: number, min: number, max: number) {
const noNegativeZero = (n: number) => (Object.is(n, -0) ? 0 : n);
if (value < min) {
return min;
return noNegativeZero(min);
}
if (value > max) {
return max;
return noNegativeZero(max);
}
return value;
return noNegativeZero(value);
}