A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://en.cppreference.com/w/cpp/language/../algorithm/../../cpp/../c/numeric/math/hypot.html below:

hypot, hypotf, hypotl - cppreference.com

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)

#define hypot( x, y )

(4) (since C99)

1-3) Computes the square root of the sum of the squares of x and y, without undue overflow or underflow at intermediate stages of the computation.

4) Type-generic macro: If any argument has type long double, the long double version of the function is called. Otherwise, if any argument has integer type or has type double, the double version of the function is called. Otherwise, the float version of the function is called.

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.

[edit] Parameters x - floating-point value y - floating-point value [edit] Return value

If no errors occur, the hypotenuse of a right-angled triangle, \(\scriptsize{\sqrt{x^2+y^2} }\)√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.

[edit] Error handling

Errors are reported as specified in math_errhandling.

If the implementation supports IEEE floating-point arithmetic (IEC 60559),

[edit] Notes

Implementations usually guarantee precision of less than 1 ulp (units in the last place): GNU, BSD.

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.

[edit] Example
#include <errno.h>
#include <fenv.h>
#include <float.h>
#include <math.h>
#include <stdio.h>
// #pragma STDC FENV_ACCESS ON
 
int main(void)
{
    // typical usage
    printf("(1,1) cartesian is (%f,%f) polar\n", hypot(1,1), atan2(1, 1));
 
    // special values
    printf("hypot(NAN,INFINITY) = %f\n", hypot(NAN, INFINITY));
 
    // error handling
    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");
}

Possible output:

(1,1) cartesian is (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
[edit] References
[edit] See also

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4