std:: hypot, std:: hypotf, std:: hypotl
|
Definiert im Header
<cmath>
|
||
| (1) | ||
|
float
hypot
(
float
x,
float
y
)
;
double
hypot
(
double
x,
double
y
)
;
|
(seit C++11)
(bis C++23) |
|
|
/*floating-point-type*/
hypot
(
/*floating-point-type*/
x,
|
(seit C++23)
(constexpr seit C++26) |
|
|
float
hypotf
(
float
x,
float
y
)
;
|
(2) |
(seit C++11)
(constexpr seit C++26) |
|
long
double
hypotl
(
long
double
x,
long
double
y
)
;
|
(3) |
(seit C++11)
(constexpr seit C++26) |
| (4) | ||
|
float
hypot
(
float
x,
float
y,
float
z
)
;
double
hypot
(
double
x,
double
y,
double
z
)
;
|
(seit C++17)
(bis C++23) |
|
|
/*floating-point-type*/
hypot
(
/*floating-point-type*/
x,
|
(seit C++23)
(constexpr seit C++26) |
|
|
Definiert im Header
<cmath>
|
||
|
template
<
class
Arithmetic1, Arithmetic2
>
/*common-floating-point-type*/
|
(A) |
(seit C++11)
(constexpr seit C++26) |
|
template
<
class
Arithmetic1, Arithmetic2, Arithmetic3
>
/*common-floating-point-type*/
|
(B) | (seit C++17) |
std::hypot
für alle cv-unqualifizierten Gleitkommatypen als Typ der Parameter
x
und
y
bereit.
(seit C++23)
std::hypot
für alle cv-unqualifizierten Gleitkommatypen als Typ der Parameter
x
,
y
und
z
bereit.
(since C++23)
Der von der zweiparametrigen Version dieser Funktion berechnete Wert ist die Länge der Hypotenuse eines rechtwinkligen Dreiecks mit den 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
.
Der von der dreiparametrigen Version dieser Funktion berechnete Wert ist der Abstand des Punktes
(x,y,z)
vom Ursprung
(0,0,0)
.
Inhaltsverzeichnis |
Parameter
| x, y, z | - | Gleitkomma- oder Ganzzahlwerte |
Rückgabewert
+y 2
, zurückgegeben.
+y 2
+z 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,
- std :: hypot ( x, y ) , std :: hypot ( y, x ) und std :: hypot ( x, - y ) sind äquivalent.
- falls eines der Argumente ±0 ist, std :: hypot ( x, y ) entspricht std::fabs aufgerufen mit dem nicht-null Argument.
- falls eines der Argumente ±∞ ist, std :: hypot ( x, y ) gibt +∞ 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 (Unit in the Last Place — Einheit der geringsten Präzision): GNU , BSD .
std :: hypot ( x, y ) ist äquivalent zu std :: abs ( std:: complex < double > ( x, y ) ) .
POSIX spezifiziert dass Unterlauf nur auftreten darf, wenn beide Argumente subnormal sind und das korrekte Ergebnis ebenfalls subnormal ist (dies verbietet naive Implementierungen).
|
Der Abstand zwischen zwei Punkten
|
(since C++17) |
Die zusätzlichen Überladungen müssen nicht exakt als (A,B) bereitgestellt werden. Sie müssen lediglich sicherstellen, dass für ihr erstes Argument num1 , zweites Argument num2 und das optionale dritte Argument num3 :
|
(bis C++23) |
|
Wenn num1 , num2 und num3 arithmetische Typen haben, dann
wobei /*common-floating-point-type*/ der Gleitkommatyp mit dem höchsten Gleitkomma-Konvertierungsrang und dem höchsten Gleitkomma-Konvertierungsunterrang unter den Typen von num1 , num2 und num3 ist; Argumente vom Ganzzahltyp werden als mit demselben Gleitkomma-Konvertierungsrang wie double betrachtet. Wenn kein solcher Gleitkommatyp mit dem höchsten Rang und Unterrang existiert, dann führt Überladungsauflösung nicht zu einem verwendbaren Kandidaten aus den bereitgestellten Überladungen. |
(seit C++23) |
| Feature-Test Makro | Wert | Std | Funktion |
|---|---|---|---|
__cpp_lib_hypot
|
201603L
|
(C++17) |
3-Argument-Überladung von
std::hypot
(4,B)
|
Beispiel
#include <cerrno> #include <cfenv> #include <cfloat> #include <cmath> #include <cstring> #include <iostream> // #pragma STDC FENV_ACCESS ON struct Point3D { float x, y, z; }; int main() { // typische Verwendung std::cout << "(1,1) kartesisch ist (" << std::hypot(1, 1) << ',' << std::atan2(1,1) << ") polar\n"; Point3D a{3.14, 2.71, 9.87}, b{1.14, 5.71, 3.87}; // C++17 verfügt über 3-Argument hypot-Überladung: std::cout << "distance(a,b) = " << std::hypot(a.x - b.x, a.y - b.y, a.z - b.z) << '\n'; // spezielle Werte std::cout << "hypot(NAN,INFINITY) = " << std::hypot(NAN, INFINITY) << '\n'; // Fehlerbehandlung errno = 0; std::feclearexcept(FE_ALL_EXCEPT); std::cout << "hypot(DBL_MAX,DBL_MAX) = " << std::hypot(DBL_MAX, DBL_MAX) << '\n'; if (errno == ERANGE) std::cout << " errno = ERANGE " << std::strerror(errno) << '\n'; if (std::fetestexcept(FE_OVERFLOW)) std::cout << " FE_OVERFLOW ausgelöst\n"; }
Ausgabe:
(1,1) kartesisch ist (1.41421,0.785398) polar
distance(a,b) = 7
hypot(NAN,INFINITY) = inf
hypot(DBL_MAX,DBL_MAX) = inf
errno = ERANGE Numerical result out of range
FE_OVERFLOW ausgelöst
Siehe auch
|
(C++11)
(C++11)
|
potenziert eine Zahl mit dem gegebenen Exponenten (
x
y
)
(Funktion) |
|
(C++11)
(C++11)
|
berechnet Quadratwurzel (
√
x
)
(Funktion) |
|
(C++11)
(C++11)
(C++11)
|
berechnet Kubikwurzel (
3
√
x
)
(Funktion) |
|
gibt den Betrag einer komplexen Zahl zurück
(Funktionstemplate) |
|
|
C-Dokumentation
für
hypot
|
|