Compute the integer and fraction parts of a floating point number.
#include <math.h> double modf(double x, double* iptr); float modff(float x, float* iptr); long double modfl(long double x, long double* iptr);
x
A floating-point value.
iptr
A pointer to the floating-point value.
These functions separate x into its integer and fractional parts. In other words, these functions separate x such that x = f + i where 0 < |f| < 1 and i equal or less than |x|.
These functions return the signed fractional part of x and store the integer part in the value pointed to by iptr.
This facility may not be available on configurations of the EWL that run on platforms that do not have floating-point math capabilities.
#include <math.h> #include <stdio.h> int main(void) { double i, f, value = 27.04; f = modf(value, &i); printf("The fractional part of %f is %f.\n", value, f); printf("The integer part of %f is %f.\n", value, i); return 0; } Output: The fractional part of 27.040000 is 0.040000. The integer part of 27.040000 is 27.000000.