Standards / Extensions | C or C++ | Dependencies |
---|---|---|
ISO C |
both |
#include <math.h>
double modf(double x, double *intptr);
float modf(float x, int *intptr); /* C++ only */
long double modf(long double x, int *intptr); /* C++ only */
float modff(float x, int *intptr);
long double modfl(long double x, int *intptr);
Breaks down the floating-point value x into fractional and integral parts. The integral part is stored as double, in the object pointed to by intptr. Both the fractional and integral parts are given the same sign as x.
Restriction
The modff() function does not support the _FP_MODE_VARIABLE feature test macro.
Returns the signed fractional portion of x.
⁄* CELEBM20
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);
}
x = -14.876000
Integral part = -14.000000
Fractional part = -0.876000