hypot(3m)
NAME
hypot, cabs − Euclidean distance, complex absolute value
SYNTAX
#include <math.h>
double hypot(x,y)
double x,y;
float fhypot(float x, float y)
double x,y;
double cabs(z)
struct {double x,y;} z;
float fcabs(z)
struct {float x,y;} z;
DESCRIPTION
The hypot, fhypot, cabs, and fcabs functions return the following:
sqrt(x∗x+y∗y)
This computation prevents underflows and overflows only occur if the final result dictates it.
The functions fhypot and fcabs are equivalent to the hypot and cabs function with the exception of float data type defined as
hypot(∞,v) = hypot(v,∞) = +∞
for all v, including NaN.
DIAGNOSTICS
If the correct value overflows, hypot returns +∞.
ERROR (due to Roundoff, etc)
Below 0.97 ulps. Consequently hypot(5.0,12.0) = 13.0 exactly; in general, hypot and cabs return an integer whenever an integer might be expected.
The same cannot be said for the shorter and faster version of hypot and cabs that is provided in the comments in cabs.c; its error can exceed 1.2 ulps.
NOTES
As might be expected, hypot(v,NaN) and hypot(NaN,v) are NaN for all finite v. Programmers might be surprised at first to discover that hypot(±∞,NaN) = +∞. This is intentional; it happens because hypot(∞,v) = +∞ for all v, finite or infinite. Hence hypot(∞,v) is independent of v. The IEEE NaN is designed to disappear when it turns out to be irrelevant, as it does in hypot(∞,NaN).
SEE ALSO
Subroutines