hypot(), hypotf(), hypotl() — Calculate the square root of the squares of two arguments

Standards

Standards / Extensions C or C++ Dependencies

SAA
XPG4
XPG4.2
C99
Single UNIX Specification, Version 3
C++ TR1 C99

both  

z/OS V1R7

Format

SAA:
#include <math.h>

double hypot(double side1, double side2);

SAA compiler option: LANGLVL(EXTENDED), LANGLVL(SAA), or LANGLVL(SAAL2)

XPG4:
#define _XOPEN_SOURCE
#include <math.h>

double hypot(double side1, double side2);
C99:
#define _ISOC99_SOURCE
#include <math.h>

float hypotf(float side1, float side2);
long double hypotl(long double side1, long double side2);
C++ TR1 C99:
#define _TR1_C99
#include <math.h>

float hypot(float side1, float side2); 
long double hypot(long double side1, long double side2);

General description

The hypot() family of functions calculates the length of the hypotenuse of a right-angled triangle based on the lengths of two sides side1 and side2. A call to hypot() is equal to:
 sqrt(side1* side1 + side2 * side2);
Note: The following table shows the viable formats for these functions. See IEEE binary floating-point for more information about IEEE Binary Floating-Point.
Function SPC Hex IEEE
hypot X X X
hypotf   X X
hypotl   X X
Restriction: The hypotf() function does not support the _FP_MODE_VARIABLE feature test macro.

Returned value

The hypot() family of functions returns the calculated length of the hypotenuse.

If the correct value is outside the range of representable values, ±HUGE_VAL is returned, according to the sign of the value. The value of the macro ERANGE is stored in errno, to show the calculated value is out of range. If the correct value would cause an underflow, zero is returned and the value of the macro ERANGE is stored in errno.

Special behavior for IEEE: If successful, The hypot() family of functions returns the calculated length of the hypotenuse. If the correct value overflows, hypot() sets errno to ERANGE and returns HUGE_VAL.

Example

CELEBH01
⁄* CELEBH01                                      

   This example calculates the hypotenuse of a right-angled                     
   triangle with sides of 3.0 and 4.0.                                          
                                                                                
 *⁄                                                                             
#include <math.h>                                                               
#include <stdio.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
The hypotenuse of the triangle with sides 3.000000 and 4.000000 is 5.000000

Related information