Splits a double precision floating-point value into fractional and integer parts.
Include
<math.h>
Prototype
double modf(double x, double *pint);
Arguments
x
pint
Return Value
Returns the signed fractional part and pint
points to the
integer part.
Remarks
The absolute value of the fractional part is in the range of 0 (inclusive) to 1 (exclusive). No domain or range error will occur.
Example
#include <math.h>
#include <stdio.h>
int main(void)
{
double x, y, n;
x = 0.707;
y = modf(x, &n);
printf("For %f the fraction is %f\n ", x, y);
printf(" and the integer is %0.f\n\n", n);
x = -15.2121;
y = modf(x, &n);
printf("For %f the fraction is %f\n ", x, y);
printf(" and the integer is %0.f\n\n", n);
}
Example Output
For 0.707000 the fraction is 0.707000
and the integer is 0
For -15.212100 the fraction is -0.212100
and the integer is -15