Standards / Extensions | C or C++ | Dependencies |
---|---|---|
C/C++ DFP | both | z/OS® V1.8 |
#define __STDC_WANT_DEC_FP__
#include <math.h>
_Decimal32 sqrtd32(_Decimal32 x);
_Decimal64 sqrtd64(_Decimal64 x);
_Decimal128 sqrtd128(_Decimal128 x);
_Decimal32 sqrt(_Decimal32 x); /* C++ only */
_Decimal64 sqrt(_Decimal64 x); /* C++ only */
_Decimal128 sqrt(_Decimal128 x); /* C++ only */
If successful, returns the square root of x.
If the correct value would cause underflow, zero is returned and the value ERANGE is stored in errno.
If x < -0, the function returns NaNQ and sets errno to EDOM.
If x is a NaN, a NaN will be returned.
If x is ±0 or +INF, x will be returned.
If x is -INF, the function returns NaNQ and sets errno to EDOM.
⁄* CELEBS71
This example illustrates the sqrtd32() function, along with
the strtod32() function.
This example computes the square root of the quantity passed
as the first argument to main.
It prints an error message if you pass a negative value.
*⁄
#define __STDC_WANT_DEC_FP__
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char ** argv)
{
char *rest;
_Decimal32 value;
if (argc != 2)
{
printf("Usage: %s value\n", argv[0]);
}
else
{
value = strtod32(argv[1], &rest);
if (value < 0.0DF)
printf("sqrt of a negative number\n");
else
printf("sqrt(%Hf) = %Hf\n", value, sqrtd32(value));
}
}