Calculate the hypotenuse.
#include <math.h>
double _hypot( double x, double y );
long double _hypotl( long double x, long double y );
x, y | Floating-point values |
The _hypot and _hypotl functions calculate the length of the hypotenuse of a right triangle, given the length of the two sides x and y (or xl and yl). A call to _hypot is equivalent to <$E size 8 sqrt size 8 { x sup 2~+~y sup 2 }>.
The _hypotl function uses the 80-bit, 10-byte coprocessor form of arguments and return values. See the reference page on the long double functions for more details on this data type.
The functions return the length of the hypotenuse. If an overflow results, the functions return HUGE_VAL and set errno to ERANGE.
_hypot
Standards:UNIX
16-Bit:DOS, QWIN, WIN, WIN DLL
32-Bit:DOS32X
Use _hypot for compatibility with ANSI naming conventions of non-ANSI functions. Use hypot and link with OLDNAMES.LIB for UNIX compatibility.
_hypotl
Standards:None
16-Bit:DOS, QWIN, WIN, WIN DLL
32-Bit:None
/* HYPOT.C: This program prints the hypotenuse of a right triangle. */
#include <math.h>
#include <stdio.h>
void 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