JavaScript Math hypot ()

Funkcja JavaScript Math.hypot () zwraca pierwiastek kwadratowy z sumy kwadratów swoich argumentów.

Wraca Math.sqrt(n1*n1 + n2*n2 +… + nx*nx).

Przedstawia odległość między punktami (n1, n2,…, nx) a początkiem.

Składnia Math.hypot()funkcji to:

 Math.hypot(n1, n2,… , nx)

hypot()jako metoda statyczna jest wywoływana przy użyciu Mathnazwy klasy.

Math.hypot () Parametry

Math.hypot()Funkcja przyjmuje w dowolnej (jeden lub więcej) liczb jako argumentów.

Wartość zwracana z Math.hypot ()

  • Zwraca pierwiastek kwadratowy z sumy kwadratów podanych argumentów.
  • Zwraca, NaNjeśli jakikolwiek argument nie jest liczbowy.
  • Zwraca +0, jeśli nie podano żadnych argumentów.

Przykład: użycie Math.hypot ()

 var num = Math.hypot(3, 4); console.log(num); // 5 var num = Math.hypot(7, 24, 25); console.log(num); // 35.35533905932738 // single argument is equivalent to absolute value var num = Math.hypot(-3); console.log(num); // 3 var num = Math.hypot(3, 4, "5"); console.log(num); // 7.0710678118654755 // returns +0 for no argument var num = Math.hypot(); console.log(num); // 0

Wynik

 5 35.35533905932738 3 7.0710678118654755 0

Zalecane lektury:

  • JavaScript Math abs ()
  • JavaScript Math sqrt ()
  • JavaScript Math pow ()

Interesujące artykuły...