modf
Return integral and fractional parts
Interface
#include <math.h>
double | modf (double value, double *iptr) |
long | modfl (long double value, long double *iptr) |
float | modff (float value, float *iptr) |
Description
The modf functions break value into the integral and fractional parts, each of which has the same sign as the argument. They return the fractional part, and store the integral part (as a floating-point number) in the object pointed to by iptr.Example:
Example - Return integral and fractional parts
Workings
#include <math.h> #include <stdio.h> int main() { double x = 31415.9265, fractional, integer; fractional = modf(x, &integer); printf("%.4lf = %.4lf + %.4lf\n", x, integer, fractional); return 0; }
Solution
Output:
31415.9265 = 31415.0000 + 0.9265
Special Values
modf ( ±∞, iptr) returns ±0 and stores ±∞ in the object pointed to by iptr. modf ( NaN, iptr) returns a NaN and stores a NaN in the object pointed to by iptr.Last Modified: 18 Dec 11 @ 13:07 Page Rendered: 2022-03-14 16:07:17