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.
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
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.hypot(x,y) = hypot(y,x), hypot(x,y) = hypot(-x,y), hypot(x,+/-0) = fabs(x), hypot(+/-Infinity, NaN) = +Infinity.
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.