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.

es.math.hypot.js 1009B

123456789101112131415161718192021222324252627282930313233343536
  1. 'use strict';
  2. var $ = require('../internals/export');
  3. // eslint-disable-next-line es/no-math-hypot -- required for testing
  4. var $hypot = Math.hypot;
  5. var abs = Math.abs;
  6. var sqrt = Math.sqrt;
  7. // Chrome 77 bug
  8. // https://bugs.chromium.org/p/v8/issues/detail?id=9546
  9. var FORCED = !!$hypot && $hypot(Infinity, NaN) !== Infinity;
  10. // `Math.hypot` method
  11. // https://tc39.es/ecma262/#sec-math.hypot
  12. $({ target: 'Math', stat: true, arity: 2, forced: FORCED }, {
  13. // eslint-disable-next-line no-unused-vars -- required for `.length`
  14. hypot: function hypot(value1, value2) {
  15. var sum = 0;
  16. var i = 0;
  17. var aLen = arguments.length;
  18. var larg = 0;
  19. var arg, div;
  20. while (i < aLen) {
  21. arg = abs(arguments[i++]);
  22. if (larg < arg) {
  23. div = larg / arg;
  24. sum = sum * div * div + 1;
  25. larg = arg;
  26. } else if (arg > 0) {
  27. div = arg / larg;
  28. sum += div * div;
  29. } else sum += arg;
  30. }
  31. return larg === Infinity ? Infinity : larg * sqrt(sum);
  32. }
  33. });