COHERENT manpages
This page displays the COHERENT manpage for hypot() [Compute hypotenuse of right triangle].
List of available manpages
Index
hypot() -- Mathematics Function (libm) Compute hypotenuse of right triangle #include <math.h> double hypot(x, y) double x, y; hypot() computes the hypotenuse, or distance from the origin, of its arguments x and y. The result is the square root of the sum of the squares of x and y. Example The following example demonstrates the functions hypot() and atan2(). It converts an X/Y pair of rectangular coordinates into polar coordinates. Thus, an X/Y pair of 1,1 produces a range of 1.41 and 45°; and an X/Y pair of 3,4 would produce a range of five and 36.87°. The following sketch illustrates this: X-Axis ^ (x,y) +-----------+ | /| | / | | e / | | g / | | n / | | a / | | R / | | / | | / | | / | |/ | Angle | +-----------+ -> Y-Axis This example was written by Brent Seidel (brent_seidel@chthone.stat.com): #include <stdio.h> #include <math.h> main() { double x, y, angle, range; char buffer[100]; printf("Enter the X/Y pair: "); fflush(stdout); gets(buffer); sscanf(buffer, "%lf,%lf", &x, &y); range = hypot(x, y); angle = atan2(x, y); printf("The range is %f\n", range); printf("The angle is %f radians or %f degrees.\n", angle, angle * 180.0/PI); } See Also cabs(), libm