Name
modf
Synopsis
Separates a floating-point number into integer and fraction parts
#include <math.h> doublemodf
( doublex
, double *intpart
); floatmodff
( floatx
, float *intpart
); (C99) long doublemodfl
( long doublex
, long double *intpart
); (C99)
The modf()
functions
analyze a floating-point number into an integer and a fraction whose
magnitude is less than one. The integer part is stored in the
location addressed by the second argument, and fractional part is
the return value.
Tip
There is no type-generic macro for the modf()
functions.
Example
double x, integer = 0.0, fraction = 0.0; x = 1.23; fraction = modf( x, &integer ); printf("%10f = %f + %f\n", x , integer, fraction ); x = -1.23; fraction = modf( x, &integer ); printf("%10f = %f + %f\n", x , integer, fraction );
The example produces the following output:
1.230000 = 1.000000 + 0.230000 -1.230000 = -1.000000 + -0.230000
See Also
Get C in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.