modfd32(), modfd64(), modfd128() — Extract fractional and integral parts of decimal floating-point value

Standards

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

Format

#define __STDC_WANT_DEC_FP__
#include <math.h>

_Decimal32  modfd32(_Decimal32 x, _Decimal32 *p); 
_Decimal64  modfd64(_Decimal64 x, _Decimal64 *x);
_Decimal128 modfd128(_Decimal128 x, _Decimal128 *x);
_Decimal32  modf(_Decimal32 x, _Decimal32 *x);   /* C++ only */
_Decimal64  modf(_Decimal64 x, _Decimal64 *x);   /* C++ only */
_Decimal128 modf(_Decimal128 x, _Decimal128 *x); /* C++ only */

General description

Breaks down the decimal floating-point value x into fractional and integral parts. The integral part is stored in the object point to by p. Both the fractional and integral parts are given the same sign as x.
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 lround functions return the signed fractional portion of x.

If the rounded value is outside the range of the return type, the numeric result is unspecified. A range error may occur if the magnitude of x is too large.

Example

⁄* CELEBM24

   This example illustrates the modfd128() function.

   This example breaks the floating-point number -14.876 into
   its fractional and integral components.

*⁄

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

int main(void)
{
  _Decimal128 x, y, d;

  x = -14.876DL;
  y = modfd128(x, &d);

  printf("Number          = %DDf\n", x);
  printf("Integral part   = %DDf\n", d);
  printf("Fractional part = %DDf\n", y);
}

Related information