Standards / Extensions | C or C++ | Dependencies |
---|---|---|
C/C++ DFP | both | z/OS® V1.8 |
#define __STDC_WANT_DEC_FP__
#include <math.h>
_Decimal32 quantized32(_Decimal32 x, _Decimal32 y);
_Decimal64 quantized64(_Decimal64 x, _Decimal64 y);
_Decimal128 quantized128(_Decimal128 x, _Decimal128 y);
The quantize functions set the exponent of argument x to the exponent of argument y, while trying to keep the value the same. If the exponent is being increased, the value is correctly rounded according to the current rounding mode. If the result does not have the same value as x, the "inexact" (FP_INEXACT) floating-point exception is raised. If the exponent is being decreased, and the significand of the result has more digits than the type would allow, the result is NaN and the "invald" (FP_INVALID) floating-point exception is raised.
If one of both operands are NaN, the result is NaN, and the "invalid" floating-point exception may be raised. Otherwise, if only one operand is infinity, the result is NaN, and the "invalid" floating-point exception is raised. If both operands are infinity, the result is DEC_INFINITY, and the sign is the same as x.
The quantize functions return the number which is equal in value (except for any rounding) and sign to x, and which has been set to be equal to the exponent of y.
⁄* CELEBQ02
This example illustrates the quantized128() function.
*⁄
#define __STDC_WANT_DEC_FP__
#include <stdio.h>
#include <math.h>
int main(void)
{
_Decimal128 price = 64999.99DL;
_Decimal128 rate = 0.09875DL;
_Decimal128 tax = quantized128(price * rate, 0.01DL);
_Decimal128 total = price + tax;
printf( "price = %22.16DDF\n"
" tax = %22.16DDF (price * rate = %-.16DDF)\n"
"total = %22.16DDF\n"
, price
, tax , price * rate
, total
);
return 0;
}