hypot, hypotf, hypotl, hypotd32, hypotd64, and hypotd128 Subroutines

Purpose

Computes the Euclidean distance function and complex absolute value.

Libraries

IEEE Math Library (libm.a) System V Math Library (libmsaa.a)

Syntax

#include <math.h>

double hypot ( x,  y)
double x, y;

float hypotf (x, y)
float x;
float y;

long double hypotl (x, y)
long double x;
long double y;
_Decimal32 hypotd32 (x, y)
_Decimal32 x, y;

_Decimal64 hypotd64 (x, y)
_Decimal64 x, y;

_Decimal128 hypotd128 (x, y)
_Decimal128 x, y;

Description

The hypot, hypotf, hypotl, hypotd32, hypotd64, and hypotd128 subroutines compute the value of the square root of x2 + y2 without undue overflow or underflow.

An application wishing to check for error situations should set the errno global variable to zero and call feclearexcept(FE_ALL_EXCEPT) before calling these subroutines. Upon return, if errno is nonzero or fetestexcept(FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW) is nonzero, an error has occurred.

Parameters

Item Description
x Specifies some double-precision floating-point value.
y Specifies some double-precision floating-point value.

Return Values

Upon successful completion, the hypot, hypotf, hypotl, hypotd32, hypotd64, and hypotd128 subroutines return the length of the hypotenuse of a right-angled triangle with sides of length x and y.

If the correct value would cause overflow, a range error occurs and the hypotf, hypotl, hypotd32, hypotd64, and hypotd128 subroutines return the value of the macro HUGE_VALF, HUGE_VALL, HUGE_VAL_D32, HUGE_VAL_D64, and HUGE_VAL_D128 respectively.

If x or y is ±Inf, +Inf is returned (even if one of x or y is NaN).

If x or y is NaN, and the other is not ±Inf, a NaN is returned.

If both arguments are subnormal and the correct result is subnormal, a range error may occur and the correct result is returned.

Error Codes

When using the libm.a (-lm) library, if the correct value overflows, the hypot subroutine returns a HUGE_VAL value.

Note: (hypot (INF, value) and hypot (value, INF) are both equal to +INF for all values, even if value = NaN.

When using libmsaa.a (-lmsaa), if the correct value overflows, the hypot subroutine returns HUGE_VAL and sets the global variable errno to ERANGE.

These error-handling procedures may be changed with the matherr subroutine when using the libmsaa.a (-lmsaa) library.