_math-scale.js 684 B

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