hypot, hypotf, hypotl
| Defined in header <math.h>
|
||
| float hypotf( float x, float y ); |
(1) | (since C99) |
| double hypot( double x, double y ); |
(2) | (since C99) |
| long double hypotl( long double x, long double y ); |
(3) | (since C99) |
| Defined in header <tgmath.h>
|
||
| #define hypot( x, y ) |
(4) | (since C99) |
x and y, without undue overflow or underflow at intermediate stages of the computation.The value computed by this function is the length of the hypotenuse of a right-angled 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.
Parameters
| x | - | floating point value |
| y | - | floating point value |
Return value
If no errors occur, the hypotenuse of a right-angled triangle, √x2
+y2
, is returned.
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.
Error handling
Errors are reported as specified in math_errhandling.
If the implementation supports IEEE floating-point arithmetic (IEC 60559),
- hypot(x, y), hypot(y, x), and hypot(x, -y) are equivalent
- if one of the arguments is ±0,
hypotis equivalent to fabs called with the non-zero argument - if one of the arguments is ±∞,
hypotreturns +∞ even if the other argument is NaN - otherwise, if any of the arguments is NaN, NaN is returned
Notes
Implementations usually guarantee precision of less than 1 ulp (units in the last place): GNU, BSD, Open64.
hypot(x, y) is equivalent to cabs(x + I*y).
POSIX specifies that underflow may only occur when both arguments are subnormal and the correct result is also subnormal (this forbids naive implementations).
hypot(INFINITY, NAN) returns +∞, but sqrt(INFINITY*INFINITY+NAN*NAN) returns NaN.