function
<cmath> <ctgmath>

modf

double modf (double x, double* intpart);
     double modf  (double x     , double* intpart);
      float modff (float x      , float* intpart);
long double modfl (long double x, long double* intpart);
     double modf (double x     , double* intpart);
      float modf (float x      , float* intpart);
long double modf (long double x, long double* intpart);
     double modf (double x     , double* intpart);
      float modf (float x      , float* intpart);
long double modf (long double x, long double* intpart);
     double modf (T x          , double* intpart);       // additional overloads
Break into fractional and integral parts
Breaks x into an integral and a fractional part.

The integer part is stored in the object pointed by intpart, and the fractional part is returned by the function.

Both parts have the same sign as x.

Additional overloads are provided in this header (<cmath>) for the integral types: These overloads effectively cast x to a double before calculations (defined for T being any integral type).

Parameters

x
Floating point value to break into parts.
intpart
Pointer to an object (of the same type as x) where the integral part is stored with the same sign as x.

Return Value

The fractional part of x, with the same sign.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
/* modf example */
#include <stdio.h>      /* printf */
#include <math.h>       /* modf */

int main ()
{
  double param, fractpart, intpart;

  param = 3.14159265;
  fractpart = modf (param , &intpart);
  printf ("%f = %f + %f \n", param, intpart, fractpart);
  return 0;
}


Output:

3.141593 = 3.000000 + 0.141593

See also