function
<cmath> <ctgmath>
hypotdouble 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 hypot (float x , float y);long double hypot (long double x, long double y); double hypot (Type1 x , Type2 y); // additional overloads
Compute hypotenuse
Returns the hypotenuse of a right-angled triangle whose legs are x and y.The function returns what would be the square root of the sum of the squares of x and y (as per the Pythagorean theorem), but without incurring in undue overflow or underflow of intermediate values.
Header
<tgmath.h>provides a type-generic macro version of this function.
are provided in this header (
<cmath>
) for other combinations of
arithmetic types(
Type1and
Type2): These overloads effectively cast its arguments to
double
before calculations, except if at least one of the arguments is of type
long double
(in which case both are casted to
long double
instead).
(x2+y2)
.
If an overflow range error occurs:
1
2
3
4
5
6
7
8
9
10
11
12
13
/* hypot example */
#include <stdio.h> /* printf */
#include <math.h> /* hypot */
int main ()
{
double leg_x, leg_y, result;
leg_x = 3;
leg_y = 4;
result = hypot (leg_x, leg_y);
printf ("%f, %f and %f form a right-angled triangle.\n",leg_x,leg_y,result);
return 0;
}
3.000000, 4.000000 and 5.000000 form a right-angled triangle.
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