modf
You can use the modf function to split a real number into a fractional part and an integer part.
float modff (float x, float *iptrf);
double modf (double x, double *iptr);
x
- Any floating-point number.
iptr
- A pointer to a floating-point variable in which the integer part can be stored upon return.
DESCRIPTION
The modf function splits its first argument into a fractional part and an integer part. This is an ANSI standard C function.
such that |f| < 1.0 and
The fractional part is returned as the value of the function, and the integer part is stored as a floating-point number in the area pointed to by iptr. The fractional part and the integer part both have the same sign as the argument x.
EXCEPTIONS
If x is finite and nonzero, the result of
is exact.
SPECIAL CASES
Table 10-19 shows the results when the floating-point argument to the modf function is a zero, a NaN, or an Infinity.
Special cases for the modf function
Operation | Result | Exceptions raised |
|
| +0 (n = 0) | None |
|
|
(n = 0) | None |
|
| NaN (n = NaN) | None[40] |
|
| +0 (n = + ) | None |
|
|
(n =
) | None |
EXAMPLES
z = modf(1.0, n); /* z = 0.0 and n = 1.0 */
z = modf(+INFINITY, n); /* z = 0.0 and n = +INFINITY because the
value +
is an integer. */
[40] If the NaN is a signaling NaN, the invalid exception is raised.