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-float-round.js 785B

1234567891011121314151617181920212223
  1. 'use strict';
  2. var sign = require('../internals/math-sign');
  3. var abs = Math.abs;
  4. var EPSILON = 2.220446049250313e-16; // Number.EPSILON
  5. var INVERSE_EPSILON = 1 / EPSILON;
  6. var roundTiesToEven = function (n) {
  7. return n + INVERSE_EPSILON - INVERSE_EPSILON;
  8. };
  9. module.exports = function (x, FLOAT_EPSILON, FLOAT_MAX_VALUE, FLOAT_MIN_VALUE) {
  10. var n = +x;
  11. var absolute = abs(n);
  12. var s = sign(n);
  13. if (absolute < FLOAT_MIN_VALUE) return s * roundTiesToEven(absolute / FLOAT_MIN_VALUE / FLOAT_EPSILON) * FLOAT_MIN_VALUE * FLOAT_EPSILON;
  14. var a = (1 + FLOAT_EPSILON / EPSILON) * absolute;
  15. var result = a - (a - absolute);
  16. // eslint-disable-next-line no-self-compare -- NaN check
  17. if (result > FLOAT_MAX_VALUE || result !== result) return s * Infinity;
  18. return s * result;
  19. };