(
Context cx, JSFunction f, Object nt, VarScope s, Object thisObj, Object[] args)
| 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) { |
no test coverage detected