Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

modf, modff, modfl - Split a number into its integer and fractional parts

&pagelevel(4)&pagelevel

Definition  

#include <math.h>

double modf(double n, double *i_p);
float modff(float n, float *i_p);
long double modfl(long double n, long double *i_p);

These functions split a floating-point number n into its integral and fractional parts. The result is the signed fraction and the integral part, the latter being returned indirectly via a result parameter i_p.

Return val.

Fractional part of n with sign.

Note

Note that the argument i_p must be a pointer!

Example

The following program resolves the number -456.789 into its integral and fractional parts.

#include <math.h>
#include <stdio.h>
int main(void)
{
  double x, g;
  x = modf(-456.789, &g);
  printf("Fraction : %g\nIntegral part : %g\n", x, g);
  return 0;
}

See also

frexp, ldexp