Defined in header <cmath>  

(1)  
float hypot ( float x, float y ); double hypot ( double x, double y ); long double hypot ( long double x, long double y );  (since C++11) (until C++23)  
/* floatingpointtype */ hypot ( /* floatingpointtype */ x, /* floatingpointtype */ y );  (since C++23) (constexpr since C++26)  
float hypotf( float x, float y );  (2)  (since C++11) (constexpr since C++26) 
long double hypotl( long double x, long double y );  (3)  (since C++11) (constexpr since C++26) 
(4)  
float hypot ( float x, float y, float z ); double hypot ( double x, double y, double z ); long double hypot ( long double x, long double y, long double z );  (since C++17) (until C++23)  
/* floatingpointtype */ hypot ( /* floatingpointtype */ x, /* floatingpointtype */ y, /* floatingpointtype */ z );  (since C++23) (constexpr since C++26)  
Additional overloads  
Defined in header <cmath>  
template< class Arithmetic1, Arithmetic2 > /* commonfloatingpointtype */ hypot ( Arithmetic1 x, Arithmetic2 y );  (A)  (since C++11) (constexpr since C++26) 
template< class Arithmetic1, Arithmetic2, Arithmetic3 > /* commonfloatingpointtype */ hypot ( Arithmetic1 x, Arithmetic2 y, Arithmetic3 z );  (B)  (since C++17) (constexpr since C++26) 
x
and y
, without undue overflow or underflow at intermediate stages of the computation. The library provides overloads of std::hypot
for all cvunqualified floatingpoint types as the type of the parameters x
and y
. (since C++23)
x
, y
, and z
, without undue overflow or underflow at intermediate stages of the computation. The library provides overloads of std::hypot
for all cvunqualified floatingpoint types as the type of the parameters x
, y
and z
. (since C++23)
The value computed by the twoargument version of this function is the length of the hypotenuse of a rightangled triangle with sides of length x
and y
, or the distance of the point (x,y)
from the origin (0,0)
, or the magnitude of a complex number x+iy
.
The value computed by the threeargument version of this function is the distance of the point (x,y,z)
from the origin (0,0,0)
.
x, y, z    floatingpoint or integer values 
If a range error due to overflow occurs, +HUGE_VAL
, +HUGE_VALF
, or +HUGE_VALL
is returned.
If a range error due to underflow occurs, the correct result (after rounding) is returned.
Errors are reported as specified in math_errhandling
.
If the implementation supports IEEE floatingpoint arithmetic (IEC 60559),
std::hypot(x, y)
, std::hypot(y, x)
, and std::hypot(x, y)
are equivalent std::hypot(x, y)
is equivalent to std::fabs
called with the nonzero argument std::hypot(x, y)
returns +∞ even if the other argument is NaN Implementations usually guarantee precision of less than 1 ulp (Unit in the Last Place — Unit of Least Precision): GNU, BSD.
std::hypot(x, y)
is equivalent to std::abs(std::complex<double>(x, y))
.
POSIX specifies that underflow may only occur when both arguments are subnormal and the correct result is also subnormal (this forbids naive implementations).
Distance between two points  (since C++17) 
The additional overloads are not required to be provided exactly as (A,B). They only need to be sufficient to ensure that for their first argument num1
, second argument num2
and the optional third argument num3
:
 (until C++23) 
If
where /* commonfloatingpointtype */ is the floatingpoint type with the greatest floatingpoint conversion rank and greatest floatingpoint conversion subrank among the types of If no such floatingpoint type with the greatest rank and subrank exists, then overload resolution does not result in a usable candidate from the overloads provided.  (since C++23) 
Featuretest macro  Value  Std  Comment 

__cpp_lib_hypot  201603L  (C++17)  3argument overload of std::hypot 
#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() { // typical usage std::cout << "(1,1) cartesian is (" << 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 has 3argument hypot overload: std::cout << "distance(a,b) = " << std::hypot(a.x  b.x, a.y  b.y, a.z  b.z) << '\n'; // special values std::cout << "hypot(NAN,INFINITY) = " << std::hypot(NAN, INFINITY) << '\n'; // error handling 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 raised\n"; }
Output:
(1,1) cartesian is (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 raised
(C++11)(C++11)  raises a number to the given power (\(\small{x^y}\)x^{y}) (function) 
(C++11)(C++11)  computes square root (\(\small{\sqrt{x} }\)√x) (function) 
(C++11)(C++11)(C++11)  computes cube root (\(\small{\sqrt[3]{x} }\)3√x) (function) 
returns the magnitude of a complex number (function template) 

C documentation for hypot 
© cppreference.com
Licensed under the Creative Commons AttributionShareAlike Unported License v3.0.
https://en.cppreference.com/w/cpp/numeric/math/hypot