samequantumd32() - samequantumd64() - samequantumd128() — Determine if Quantum Exponents X and Y are the Same
Format
#define __STDC_WANT_DEC_FP__
#include <math.h>
_Bool samequantumd32(_Decimal32 x, _Decimal32 y);
_Bool samequantumd64(_Decimal64 x, _Decimal64 y);
_Bool samequantumd128(_Decimal128 x, _Decimal128 y);
Language Level
ANSI
Threadsafe
Yes
Description
The samequantumd32()
, samequantumd64()
,
and samequantumd128()
functions
determine if the quantum exponents of x and y are the
same. If both x and y are NaN or both x and y are
infinity, they have the same quantum exponents. If exactly one operand
is infinity or exactly one operand is NaN, they do not have the same
quantum exponents. The samequantumd32(), samequantumd64(), and samequantumd128()
functions raise no floating-point exceptions.
Return Value
The samequantumd32()
, samequantumd64()
,
and samequantumd128()
functions
return true when x and y have the same quantum exponents,
and false otherwise.
Example
This example illustrates the use
of the samequantumd64() function.
#define __STDC_WANT_DEC_FP__
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
static void dump_value(_Decimal64 val1, _Decimal64 val2)
{
printf( " quantexp(x)=%d quantexp(y)=%d samequantum=%d\n",
quantexpd64(val1), quantexpd64(val2),
(int)samequantumd64(val1, val2) );
}
int main(void)
{
_Decimal64 a1 = strtod64("1.23", NULL);
_Decimal64 a2 = strtod64("0.01", NULL);
_Decimal64 b1 = strtod64("1.234", NULL);
_Decimal64 b2 = strtod64("0.01", NULL);
_Decimal64 c1 = strtod64("1.000", NULL);
_Decimal64 c2 = strtod64("1.00", NULL);
_Decimal64 d1 = strtod64("0.000", NULL);
_Decimal64 d2 = strtod64("0.00", NULL);
printf( "x=%-8Da y=%-8Da\n", a1, a2 );
dump_value(a1, a2);
printf( "x=%-8Da y=%-8Da\n", b1, b2 );
dump_value(b1, b2);
printf( "x=%-8Da y=%-8Da\n", c1, c2 );
dump_value(c1, c2);
printf( "x=%-8Da y=%-8Da\n", d1, d2 );
dump_value(d1, d2);
return 0;
}
/***************** Output should be similar to: *****************
x=1.23 y=0.01
quantexp(x)=-2 quantexp(y)=-2 samequantum=1
x=1.234 y=0.01
quantexp(x)=-3 quantexp(y)=-2 samequantum=0
x=1.000 y=1.00
quantexp(x)=-3 quantexp(y)=-2 samequantum=0
x=0.000 y=0.00
quantexp(x)=-3 quantexp(y)=-2 samequantum=0
*/