hypot(), cabs(), z_abs() - euclidean distance and complex absolute value functions
#include <math.h>
double hypot (double x, double y)
struct complex {double x, y;} z;
double cabs (z)
double z_abs (struct z *z)
The hypot(3), cabs(3), and z_abs(3) functions compute the sqrt(x*x+y*y) in such a way that underflow will not happen, and overflow occurs only if the final result deserves it.
hypot(Infinity,v) = hypot(v,Infinity) = +Infinity for all v, including NaN.
The z_abs(3) function is similar to cabs(3) except that it takes a pointer to a struct z rather than the structure itself.
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.
Given the following:
#include <math.h>
double a, b, r;
complex z;
a = 2.0;
b = 3.0;
z.x = 2.0;
z.y = 3.0;
The following give identical values for r:
r = hypot(a, b);
r = cabs(z);
r = z_abs(&z);
On success, hypot(3), cabs(3), and z_abs(3) return the length of the hypotenuse of a right-angled triangle with sides of length x and y.
If the result would cause overflow, they return NaN and set errno. If x or y is NaN, they return NaN and set errno.
These functions can fail for the following reasons:
math(3)
sqrt(3)