sqrt, sqrtf, sqrtl, sqrtd32, sqrtd64, and sqrtd128 Subroutines

Purpose

Computes the square root.

Syntax

#include <math.h>
double sqrt ( x)
double x;
float sqrtf (x)
float x;
long double sqrtl (x)
long double x;
_Decimal32 sqrtd32 (x)
_Decimal32 x;

_Decimal64 sqrtd64 (x)
_Decimal64 x;

_Decimal128 sqrtd128 (x)
_Decimal128 x;

Description

The sqrt, sqrtf, sqrtl, sqrtd32, sqrtd64, and sqrtd128 subroutines compute the square root of the x parameter.

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.

Return Values

Upon successful completion, the sqrt, sqrtf, sqrtl, sqrtd32, sqrtd64, and sqrtd128 subroutines return the square root of x.

For finite values of x < -0, a domain error occurs, and a NaN is returned.

If x is NaN, a NaN is returned.

If x is ±0 or +Inf, x is returned.

If x is -Inf, a domain error shall occur, and a NaN is returned.

Error Codes

When using libm.a (-lm):

For the sqrt subroutine, if the value of x is negative, a NaNQ is returned and the errno global variable is set to a EDOM value.

When using libmsaa.a (-lmsaa):

If the value of x is negative, a 0 is returned and the errno global variable is set to a EDOM value. A message indicating a DOMAIN error is printed on the standard error output.

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