December 2005
Beginner to intermediate
618 pages
20h 19m
English
modf
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.
There is no type-generic macro for the modf() functions.
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
Read now
Unlock full access