Node-Red configuration
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

math-scale.js 621B

1234567891011121314
  1. 'use strict';
  2. // `Math.scale` method implementation
  3. // https://rwaldron.github.io/proposal-math-extensions/
  4. module.exports = Math.scale || function scale(x, inLow, inHigh, outLow, outHigh) {
  5. var nx = +x;
  6. var nInLow = +inLow;
  7. var nInHigh = +inHigh;
  8. var nOutLow = +outLow;
  9. var nOutHigh = +outHigh;
  10. // eslint-disable-next-line no-self-compare -- NaN check
  11. if (nx !== nx || nInLow !== nInLow || nInHigh !== nInHigh || nOutLow !== nOutLow || nOutHigh !== nOutHigh) return NaN;
  12. if (nx === Infinity || nx === -Infinity) return nx;
  13. return (nx - nInLow) * (nOutHigh - nOutLow) / (nInHigh - nInLow) + nOutLow;
  14. };