Rediģēt

Kopīgot, izmantojot


hypot, hypotf, hypotl, _hypot, _hypotf, _hypotl

Calculates the hypotenuse.

Syntax

double hypot(
   double x,
   double y
);
float hypotf(
   float x,
   float y
);
long double hypotl(
   long double x,
   long double y
);
double _hypot(
   double x,
   double y
);
float _hypotf(
   float x,
   float y
);
long double _hypotl(
   long double x,
   long double y
);
#define hypotf(X, Y) // Requires C11 or higher

Parameters

x, y
Floating-point values.

Return value

If successful, hypot returns the length of the hypotenuse; on overflow, hypot returns INF (infinity) and the errno variable is set to ERANGE. You can use _matherr to modify error handling.

For more information about return codes, see errno, _doserrno, _sys_errlist, and _sys_nerr.

Remarks

The hypot functions calculate the length of the hypotenuse of a right triangle, given the length of the two sides x and y (in other words, the square root of x2 + y2).

The versions of the functions that have leading underscores are provided for compatibility with earlier standards. Their behavior is identical to the versions that don't have leading underscores. We recommend using the versions without leading underscores for new code.

If you use the <tgmath.h> hypot() macro, the type of the argument determines which version of the function is selected. See Type-generic math for details.

By default, this function's global state is scoped to the application. To change this behavior, see Global state in the CRT.

Requirements

Routine Required header
hypot, hypotf, hypotl, _hypot, _hypotf, _hypotl <math.h>
hypot macro <tgmath.h>

For more compatibility information, see Compatibility.

Example

// crt_hypot.c
// This program prints the hypotenuse of a right triangle.

#include <math.h>
#include <stdio.h>

int main( void )
{
   double x = 3.0, y = 4.0;

   printf( "If a right triangle has sides %2.1f and %2.1f, "
           "its hypotenuse is %2.1f\n", x, y, _hypot( x, y ) );
}
If a right triangle has sides 3.0 and 4.0, its hypotenuse is 5.0

See also

Math and floating-point support
_cabs
_matherr