HYPOT 3CW "09 March 2006" "mathcw-1.00"

Table of contents


NAME

hypotf, hypot, hypotl, hypotw, hypotq, hypotll, hypotdf, hypotd, hypotdl, hypotdll - Euclidean distance

SYNOPSIS

cc [ flags ] -I/usr/local/include file(s) -L/usr/local/lib -lmcw [ ... ]

#include <mathcw.h>

extern float hypotf (float x, float y);

extern double hypot (double x, double y);

extern long double hypotl (long double x, long double y);

extern __float80 hypotw (__float80 x, __float80 y);

extern __float128 hypotq (__float128 x, __float128 y);

extern long_long_double hypotll (long_long_double x, long_long_double y);

extern decimal_float hypotdf (decimal_float x, decimal_float y);

extern decimal_double hypotd (decimal_double x, decimal_double y);

extern decimal_long_double hypotdl (decimal_long_double x, decimal_long_double y);

extern decimal_long_long_double hypotdll (decimal_long_long_double x, decimal_long_long_double y);

NB: Functions with prototypes containing underscores in type names may be available only with certain extended compilers.


DESCRIPTION

Compute the square root of the sum of the squares of the two arguments without undue overflow or underflow.

Caution: The mathematically-equivalent formula sqrt(x*x + y*y) is not robust, because it is subject to premature overflow and underflow, and should not be used.

The C99 Standard requires that

hypot(x,y) = hypot(y,x),
hypot(x,y) = hypot(-x,y),
hypot(x,+/-0) = fabs(x),
hypot(+/-Infinity, NaN) = +Infinity.
The peculiar requirement of the latter is justified on the (questionable) grounds that hypot(+/-Infinity, y) = +Infinity for any finite or infinite y, so it should also hold if one of the arguments is a NaN.

RETURN VALUES

The value returned is an accurate value of sqrt(x*x + y*y).

ERRORS

If either argument is +/-Infinity, the result is +Infinity, and errno is set to ERANGE.

If either argument is a NaN, and neither is Infinity, the result is that argument, and errno is set to EDOM.

If the computed result is infinite, then errno is set to ERANGE.


SEE ALSO

sqrt(3CW).