samequantumd32(), samequantumd64(), samequantumd128() — Determine if exponents X and Y are the same

Standards

Standards / Extensions C or C++ Dependencies
C/C++ DFP both z/OS® V1.8

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);

General description

The samequantum functions determine if the representation exponents of x and y are the same. If both x and y are NaN or infinity, they have the same representation exponents. If exactly one operand is infinity or exactly one operand is NaN, they do not have the same representation exponents. The samequantum functions raise no floating point exceptions.

Argument Description
x First input value
y Second input value
Note:
  • To use IEEE decimal floating-point, the hardware must have the Decimal Floating-Point Facility installed.
  • These functions work in IEEE decimal floating-point format. See "IEEE Decimal Floating-Point" for more information.

Returned value

The samequantum functions return true when x and y have the same representation exponents, and false otherwise.

Example

⁄* CELEBS72

   This example illustrates the samequantumd64() function

*⁄

#define  __STDC_WANT_DEC_FP__
#include <math.h>
#include <stdio.h>
#include <stdlib.h>

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=%-8.2DF y=%-8.2DF samequantum=%d\n"
          "x=%-8.3DF y=%-8.2DF samequantum=%d\n"
          "x=%-8.3DF y=%-8.2DF samequantum=%d\n"
          "x=%-8.3DF y=%-8.2DF samequantum=%d\n"

        ,  a1, a2, (int)samequantumd64(a1, a2)
        ,  b1, b2, (int)samequantumd64(b1, b2)
        ,  c1, c2, (int)samequantumd64(c1, c2)
        ,  d1, d2, (int)samequantumd64(d1, d2)
        );

  return 0;
}

Related information