C <math.h> - modf() Function
The C <math.h> modf() function is used to break x into an integral and a fractional part. The integer part is stored in the object pointed by pointer y, and the fractional part is returned by the function. Both parts have the same sign as x.
Syntax
double modf (double x, double* y); float modff (float x, float* y); long double modfl (long double x, long double* y);
Parameters
x |
Specify the floating point value to break into parts. |
y |
Specify the pointer to an object (of the same type as x) to store the integral part with the same sign as x. |
Return Value
The fractional part of the x with same sign as of x.
Example:
The example below shows the usage of modf() function.
#include <stdio.h> #include <math.h> int main (){ double x, y, z; x = 10.55; z = modf(x, &y); printf("Number: %lf\n", x); printf("Integer: %lf\n", y); printf("Fraction: %lf\n", z); return 0; }
The output of the above code will be:
Number: 10.550000 Integer: 10.000000 Fraction: 0.550000
❮ C <math.h> Library