|
|
|
Defined in header <math.h> | ||
float roundevenf(float arg); | (1) | (since C23) |
double roundeven(double arg); | (2) | (since C23) |
longdouble roundevenl(longdouble arg); | (3) | (since C23) |
Defined in header <tgmath.h> | ||
#define roundeven( arg ) | (4) | (since C23) |
roundevenl
is called. Otherwise, ifarg has integer type or the typedouble,roundeven
is called. Otherwise,roundevenf
is called, respectively.Contents |
arg | - | floating-point value |
If no errors occur, the nearest integer value toarg, rounding halfway cases to nearest even integer, is returned.
This function is not subject to any of the errors specified inmath_errhandling
.
If the implementation supports IEEE floating-point arithmetic (IEC 60559):
#include <math.h>#include <stdio.h> int main(void){printf("roundeven(+2.4) = %+.1f\n", roundeven(2.4));printf("roundeven(-2.4) = %+.1f\n", roundeven(-2.4));printf("roundeven(+2.5) = %+.1f\n", roundeven(2.5));printf("roundeven(-2.5) = %+.1f\n", roundeven(-2.5));printf("roundeven(+2.6) = %+.1f\n", roundeven(2.6));printf("roundeven(-2.6) = %+.1f\n", roundeven(-2.6));printf("roundeven(+3.5) = %+.1f\n", roundeven(3.5));printf("roundeven(-3.5) = %+.1f\n", roundeven(-3.5));printf("roundeven(-0.0) = %+.1f\n", roundeven(-0.0));printf("roundeven(-Inf) = %+f\n", roundeven(-INFINITY));}
Possible output:
roundeven(+2.4) = +2.0roundeven(-2.4) = -2.0roundeven(+2.5) = +2.0roundeven(-2.5) = -2.0roundeven(+2.6) = +3.0roundeven(-2.6) = -3.0roundeven(+3.5) = +4.0roundeven(-3.5) = -4.0roundeven(-0.0) = -0.0roundeven(-Inf) = -inf
(C99)(C99)(C99)(C99)(C99)(C99)(C99)(C99)(C99) | rounds to an integer using current rounding mode with exception if the result differs (function)[edit] |
(C99)(C99)(C99)(C99)(C99)(C99)(C99)(C99)(C99) | rounds to nearest integer, rounding away from zero in halfway cases (function)[edit] |