hypot, hypotf, cabs, cabsf - Euclidean distance and complex
absolute value
functions
#include <math.h>
double
hypot(double x, double y);
float
hypotf(float x, float y);
double
cabs(struct complex { double x; double y; } z);
float
cabsf(struct complex { float x; float y; } z);
The hypot() and cabs() 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. The hypotf() and cabsf() functions are
single precision
versions of hypot() and cabs(), respectively.
hypot(Infinity, v) = hypot(v, Infinity) = +Infinity for all
v, including
NaN.
ERRORS (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.
As might be expected, hypot(v, NaN) and hypot(NaN, v) are
NaN for all
finite v; with "reserved operand" in place of "NaN", the
same is true on
a VAX. But programmers on machines other than a VAX (it has
no Infinity)
might be surprised at first to discover that
hypot(+-Infinity, NaN) =
+Infinity. This is intentional; it happens because
hypot(Infinity, v) =
+Infinity for all v, finite or infinite. Hence
hypot(Infinity, v) is independent
of v. Unlike the reserved operand fault on a VAX,
the IEEE NaN
is designed to disappear when it turns out to be irrelevant,
as it does
in hypot(Infinity, NaN).
math(3), sqrt(3)
Both a hypot() function and a cabs() function appeared in
Version 7 AT&T
UNIX.
The cabs() and cabsf() functions use structures that are not
defined in
any header and need to be defined by the user. As such they
cannot be
prototyped properly.
OpenBSD 3.6 May 6, 1991
[ Back ] |