MCPcopy Create free account
hub / github.com/mozilla/rhino / hypot

Method hypot

rhino/src/main/java/org/mozilla/javascript/NativeMath.java:425–454  ·  view source on GitHub ↗
(
            Context cx, JSFunction f, Object nt, VarScope s, Object thisObj, Object[] args)

Source from the content-addressed store, hash-verified

423 // Based on code from
424 // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/hypot
425 private static Object hypot(
426 Context cx, JSFunction f, Object nt, VarScope s, Object thisObj, Object[] args) {
427 if (args == null) {
428 return 0.0;
429 }
430 double y = 0.0;
431
432 // Spec and tests say that any "Infinity" result takes precedence.
433 boolean hasNaN = false;
434 boolean hasInfinity = false;
435
436 for (Object o : args) {
437 double d = ScriptRuntime.toNumber(o);
438 if (Double.isNaN(d)) {
439 hasNaN = true;
440 } else if (Double.isInfinite(d)) {
441 hasInfinity = true;
442 } else {
443 y += d * d;
444 }
445 }
446
447 if (hasInfinity) {
448 return Double.POSITIVE_INFINITY;
449 }
450 if (hasNaN) {
451 return Double.NaN;
452 }
453 return Math.sqrt(y);
454 }
455
456 private static Object imul(
457 Context cx, JSFunction f, Object nt, VarScope s, Object thisObj, Object[] args) {

Callers 1

math-functions.jsFile · 0.80

Calls 3

toNumberMethod · 0.95
sqrtMethod · 0.80
isNaNMethod · 0.45

Tested by

no test coverage detected