hypot() — Calculate Hypotenuse

Format

#include <math.h>
double hypot(double side1, double side2);

Language Level: ILE C Extension

Threadsafe: Yes.

Description

The hypot() function calculates the length of the hypotenuse of a right-angled triangle based on the lengths of two sides side1 and side2. A call to the hypot() function is equivalent to:

   sqrt(side1 * side1 + side2 * side2);

Return Value

The hypot() function returns the length of the hypotenuse. If an overflow results, hypot() sets errno to ERANGE and returns the value HUGE_VAL. If an underflow results, hypot() sets errno to ERANGE and returns zero. The value of errno can also be set to EDOM.

Example that uses hypot()

This example calculates the hypotenuse of a right-angled triangle with sides of 3.0 and 4.0.

#include <math.h>
 
int main(void)
{
   double x, y, z;
 
   x = 3.0;
   y = 4.0;
   z = hypot(x,y);
 
   printf("The hypotenuse of the triangle with sides %lf and %lf"
          " is %lf\n", x, y, z);
}
 
/********************  Output should be similar to:  **************
 
The hypotenuse of the triangle with sides 3.000000 and 4.000000 is 5.000000
*/

Related Information



[ Top of Page | Previous Page | Next Page | Contents | Index ]