.TH hypot() "" "" "Mathematics Function (libm)"
.PC "Compute hypotenuse of right triangle"
.B "#include <math.h>"
\fBdouble hypot(\fIx\^\fB, \fIy\^\fB) double \fIx\^\fB, \fIy\^\fB;\fR
.PP
.B hypot()
computes the hypotenuse, or distance from the origin, of its arguments
.I x
and
.IR y .
The result is the square root of the sum of the squares of
.I x
and
.IR y .
.SH Example
The following example demonstrates the functions
.B hypot()
and
.BR 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\(de;
and an X/Y pair of 3,4 would produce a range of five and 36.87\(de.
The following sketch illustrates this:
.ie p .PH 1 1 \\*(XD/hypot.eps
.el  \{
.ie \n(HT .PH hypot.xbm
.el \{
.DM
	X-Axis
	\(ua            (x,y)
	+-----------+
	|          /|
	|         / |
	|      e /  |
	|     g /   |
	|    n /    |
	|   a /     |
	|  R /      |
	|   /       |
	|  /        |
	| /         |
	|/  | Angle |
	+-----------+  \(-> Y-Axis
.DE\}
\}
.PP
.II "Seidel, Brent"
This example was written by Brent Seidel (brent_seidel@chthone.stat.com):
.DM
#include <stdio.h>
#include <math.h>
.DE
.DM
main()
{
	double x, y, angle, range;
	char	buffer[100];
.DE
.DM
	printf("Enter the X/Y pair: ");
	fflush(stdout);
	gets(buffer);
	sscanf(buffer, "%lf,%lf", &x, &y);
.DE
.DM
	range = hypot(x, y);
	angle = atan2(x, y);
	printf("The range is %f\en", range);
	printf("The angle is %f radians or %f degrees.\en",
		angle, angle * 180.0/PI);
}
.DE
.SH "See Also"
.Xr "cabs()," cabs
.Xr "libm" libm
