quantized32() - quantized64() - quantized128() — Set the Quantum Exponent of X to the Quantum Exponent of Y
Format
#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); Language Level
ANSI
Threadsafe
Yes
Description
The quantized32(), quantized64(),
and quantized128() functions
set the quantum exponent of argument x to the quantum exponent
of argument y, while trying to keep the value the same. If
the quantum exponent is being increased, the value is correctly rounded
according to the rounding mode Round to Nearest, Ties to Even. If
the result does not have the same value as x, the ″inexact″
floating-point exception is raised. If the quantum exponent is being
decreased, and the significand of the result has more digits than
the type would allow, the result is NaN and the ″invalid″ floating-point
exception is raised.
If one or 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 infinity and the sign is the same as x.
The quantized32(), quantized64(),
and quantized128() functions
do not signal underflow or overflow.
Return Value
The quantized32(), quantized64(),
and quantized128() functions
return the number which is equal in value (except for any rounding)
and sign to x, and which has a quantum exponent equal to the
quantum exponent of y.
Example
#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 = %DDa\n"
" tax = %DDa (price * rate = %DDa)\n"
"total = %DDa\n",
price, tax, price * rate, total );
return 0;
}
/***************** Output should be similar to: *****************
price = 64999.99
tax = 6418.75 (price * rate = 6418.7490125)
total = 71418.74
*/