modf(), modff(), modfl() — Extract fractional and integral parts of floating-point value

Standards

Standards / Extensions C or C++ Dependencies

ISO C
POSIX.1
XPG4
XPG4.2
ISO/ANSI C++
C99
Single UNIX Specification, Version 3
C++ TR1 C99

both  

Format

#include <math.h>

double modf(double x, double *intptr);
float modf(float x, int *intptr);               /* C++ only */
long double modf(long double x, int *intptr);   /* C++ only */
float modff(float x, int *intptr);
long double modfl(long double x, int *intptr);

General description

Breaks down the floating-point value x into fractional and integral parts. The integral part is stored as double, in the object pointed to by intptr. Both the fractional and integral parts are given the same sign as x.

Restriction

The modff() function does not support the _FP_MODE_VARIABLE feature test macro.

Returned value

Returns the signed fractional portion of x.

Example

CELEBM20
⁄* CELEBM20                                      

   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);                                        
}                                                                               
Output
x = -14.876000
Integral part = -14.000000
Fractional part = -0.876000

Related information