UNPKG

557 BJavaScriptView Raw
1// `Math.scale` method implementation
2// https://rwaldron.github.io/proposal-math-extensions/
3module.exports = Math.scale || function scale(x, inLow, inHigh, outLow, outHigh) {
4 if (
5 arguments.length === 0
6 /* eslint-disable no-self-compare */
7 || x != x
8 || inLow != inLow
9 || inHigh != inHigh
10 || outLow != outLow
11 || outHigh != outHigh
12 /* eslint-enable no-self-compare */
13 ) return NaN;
14 if (x === Infinity || x === -Infinity) return x;
15 return (x - inLow) * (outHigh - outLow) / (inHigh - inLow) + outLow;
16};