Format
#include <math.h>
double modf(double x, double *intptr);
Language Level: ANSI
Threadsafe: Yes.
Description
The modf() function breaks down the floating-point value x into fractional and integral parts. The signed fractional portion of x is returned. The integer portion is stored as a double value pointed to by intptr. Both the fractional and integral parts are given the same sign as x.
Return Value
The modf() function returns the signed fractional portion of x.
Example that uses modf()
This example breaks the floating-point number -14.876 into its fractional and integral components.
#include <math.h>
#include <stdio.h>
int main(void)
{
double x, y, d;
x = -14.876;
y = modf(x, &d);
printf("x = %lf\n", x);
printf("Integral part = %lf\n", d);
printf("Fractional part = %lf\n", y);
}
/**************** Output should be similar to: ******************
x = -14.876000
Integral part = -14.000000
Fractional part = -0.876000
*/
Related Information