hypot, hypotf, hypotl
|
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Definiert im Header
<math.h>
|
||
|
float
hypotf
(
float
x,
float
y
)
;
|
(1) | (seit C99) |
|
double
hypot
(
double
x,
double
y
)
;
|
(2) | (seit C99) |
|
long
double
hypotl
(
long
double
x,
long
double
y
)
;
|
(3) | (seit C99) |
|
Definiert im Header
<tgmath.h>
|
||
|
#define hypot( x, y )
|
(4) | (seit C99) |
Der von dieser Funktion berechnete Wert ist die Länge der Hypotenuse eines rechtwinkligen Dreiecks mit Seitenlängen
x
und
y
, oder der Abstand des Punktes
(
x, y
)
vom Ursprung
(
0
,
0
)
, oder der Betrag einer komplexen Zahl
x+
i
y
.
Inhaltsverzeichnis |
Parameter
| x | - | Fließkommawert |
| y | - | Fließkommawert |
Rückgabewert
Wenn keine Fehler auftreten, wird die Hypotenuse eines rechtwinkligen Dreiecks,
\(\scriptsize{\sqrt{x^2+y^2} }\)
√
x
2
+y
2
, zurückgegeben.
Wenn ein Bereichsfehler aufgrund von Überlauf auftritt,
+HUGE_VAL
,
+HUGE_VALF
, oder
+HUGE_VALL
wird zurückgegeben.
Wenn ein Bereichsfehler aufgrund von Unterlauf auftritt, wird das korrekte Ergebnis (nach Rundung) zurückgegeben.
Fehlerbehandlung
Fehler werden gemeldet, wie in
math_errhandling
spezifiziert.
Wenn die Implementierung IEEE-Gleitkommaarithmetik (IEC 60559) unterstützt,
- hypot ( x, y ) , hypot ( y, x ) und hypot ( x, - y ) sind äquivalent
-
falls eines der Argumente ±0 ist, ist
hypotäquivalent zu fabs aufgerufen mit dem nicht-null Argument -
falls eines der Argumente ±∞ ist, gibt
hypot+∞ zurück, selbst wenn das andere Argument NaN ist - andernfalls, falls eines der Argumente NaN ist, wird NaN zurückgegeben.
Hinweise
Implementierungen garantieren üblicherweise eine Genauigkeit von weniger als 1 ulp ( units in the last place ): GNU , BSD .
hypot ( x, y ) ist äquivalent zu cabs ( x + I * y ) .
POSIX spezifiziert dass Unterlauf nur auftreten darf, wenn beide Argumente subnormal sind und das korrekte Ergebnis ebenfalls subnormal ist (dies verbietet naive Implementierungen).
hypot ( INFINITY, NAN ) gibt +∞ zurück, aber sqrt ( INFINITY * INFINITY + NAN * NAN ) gibt NaN zurück.
Beispiel
#include <errno.h> #include <fenv.h> #include <float.h> #include <math.h> #include <stdio.h> // #pragma STDC FENV_ACCESS ON int main(void) { // typische Verwendung printf("(1,1) kartesisch ist (%f,%f) polar\n", hypot(1,1), atan2(1, 1)); // spezielle Werte printf("hypot(NAN,INFINITY) = %f\n", hypot(NAN, INFINITY)); // Fehlerbehandlung errno = 0; feclearexcept(FE_ALL_EXCEPT); printf("hypot(DBL_MAX,DBL_MAX) = %f\n", hypot(DBL_MAX, DBL_MAX)); if (errno == ERANGE) perror(" errno == ERANGE"); if (fetestexcept(FE_OVERFLOW)) puts(" FE_OVERFLOW raised"); }
Mögliche Ausgabe:
(1,1) kartesisch ist (1.414214,0.785398) polar
hypot(NAN,INFINITY) = inf
hypot(DBL_MAX,DBL_MAX) = inf
errno == ERANGE: Numerical result out of range
FE_OVERFLOW raised
Referenzen
- C23-Standard (ISO/IEC 9899:2024):
-
- 7.12.7.3 Die hypot-Funktionen (S.: TBD)
-
- 7.25 Typgenerische Mathematik <tgmath.h> (S.: TBD)
-
- F.10.4.3 Die hypot-Funktionen (S.: TBD)
- C17-Standard (ISO/IEC 9899:2018):
-
- 7.12.7.3 Die hypot-Funktionen (S: 181)
-
- 7.25 Typgenerische Mathematik <tgmath.h> (S: 272-273)
-
- F.10.4.3 Die hypot-Funktionen (S: 382)
- C11-Standard (ISO/IEC 9899:2011):
-
- 7.12.7.3 Die hypot-Funktionen (S: 248)
-
- 7.25 Typgenerische Mathematik <tgmath.h> (S: 373-375)
-
- F.10.4.3 Die hypot-Funktionen (S: 524)
- C99-Standard (ISO/IEC 9899:1999):
-
- 7.12.7.3 Die hypot-Funktionen (S. 229)
-
- 7.22 Typgenerische Mathematik <tgmath.h> (S. 335-337)
-
- F.9.4.3 Die hypot-Funktionen (S. 461)
Siehe auch
|
(C99)
(C99)
|
berechnet eine Zahl potenziert mit dem gegebenen Exponenten (
\(\small{x^y}\)
x
y
)
(Funktion) |
|
(C99)
(C99)
|
berechnet Quadratwurzel (
\(\small{\sqrt{x} }\)
√
x
)
(Funktion) |
|
(C99)
(C99)
(C99)
|
berechnet Kubikwurzel (
\(\small{\sqrt[3]{x} }\)
3
√
x
)
(Funktion) |
|
(C99)
(C99)
(C99)
|
berechnet den Betrag einer komplexen Zahl
(Funktion) |
|
C++-Dokumentation
für
hypot
|
|