modf -- Separate Floating-Point Value

Format

#include <math.h>
double modf(double x, double *intptr);
float modf(float x, float *intptr);
long double modf(long double x, long double *intptr);
float modf(float x, float *intptr);
long double modf(long double x, long double *intptr);

Language Level: ANSI, POSIX, XPG4
modf breaks down the floating-point value x into fractional and integral parts. The signed fractional portion of x is returned. The integer portion is stored as a double value pointed to by intptr. Both the fractional and integral parts are given the same sign as x.

Note: C++ prototypes

float modf(float x, float *intptr);
long double modf(long double x, long double *intptr);

are disabled when you compile using the lang(compatmath) option.

Return Value
modf returns the signed fractional portion of x.

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

#include <math.h>
#include <stdio.h>
int main(void)
{
   double x, y, d;
   x = -14.876;
   y = modf(x, &d);
   printf("x = %lf\n", x);
   printf("Integral part = %lf\n", d);
   printf("Fractional part = %lf\n", y);
   return 0;
   /**************************************
      The output should be:
      x = -14.876000
      Integral part = -14.000000
      Fractional part = -0.876000
   **************************************/
}


fmod -- Calculate Floating-Point Remainder
frexp -- Separate Floating-Point Value
ldexp -- Multiply by a Power of Two
<math.h>
lang(compatmath) option