modf, modff, modfl
From cppreference.com
Defined in header <math.h>
|
||
float modff( float arg, float* iptr ); |
(1) | (since C99) |
double modf( double arg, double* iptr ); |
(2) | |
long double modfl( long double arg, long double* iptr ); |
(3) | (since C99) |
1-3) Decomposes given floating point value
arg
into integral and fractional parts, each having the same type and sign as arg
. The integral part (in floating-point format) is stored in the object pointed to by iptr
.Parameters
arg | - | floating point value |
iptr | - | pointer to floating point value to store the integral part to |
Return value
If no errors occur, returns the fractional part of x
with the same sign as x
. The integral part is put into the value pointed to by iptr
.
The sum of the returned value and the value stored in *iptr
gives arg
(allowing for rounding).
Error handling
This function is not subject to any errors specified in math_errhandling.
If the implementation supports IEEE floating-point arithmetic (IEC 60559),
- If
arg
is ±0, ±0 is returned, and ±0 is stored in *iptr. - If
arg
is ±∞, ±0 is returned, and ±∞ is stored in *iptr. - If
arg
is NaN, NaN is returned, and NaN is stored in *iptr. - The returned value is exact, the current rounding mode is ignored
Notes
This function behaves as if implemented as follows:
double modf(double value, double *iptr) { #pragma STDC FENV_ACCESS ON int save_round = fegetround(); fesetround(FE_TOWARDZERO); *iptr = std::nearbyint(value); fesetround(save_round); return copysign(isinf(value) ? 0.0 : value - (*iptr), value); }