modf, modfl
Go Up to math.h Index
Header File
math.h
Category
Math Routines
Prototype
double modf(double x, double *ipart);
long double modfl(long double x, long double *ipart);
Description
Splits a double or long double into integer and fractional parts.
modf breaks the double x into two parts: the integer and the fraction. modf stores the integer in ipart and returns the fraction.
modfl is the long double version; it takes long double arguments and returns a long double result.
Return Value
modf and modfl return the fractional part of x.
Example
#include <math.h> #include <stdio.h> int main(void) { double fraction, integer; double number = 100000.567; fraction = modf(number, &integer); printf("The whole and fractional parts of %lf are %lf and %lf\n", number, integer, fraction); return 0; }
Portability
POSIX | Win32 | ANSI C | ANSI C++ | |
---|---|---|---|---|
modf |
+ |
+ |
+ |
+ |
modfl |
+ |
+ |
+ |