roundeven, roundevenf, roundevenl

Header: <math.h>

1-3) Computes the nearest integer value to arg (in floating-point format), rounding halfway cases to nearest even integer, regardless of the current rounding mode.

# Declarations

float roundevenf( float arg );

(since C23)

double roundeven( double arg );

(since C23)

long double roundevenl( long double arg );

(since C23)

#define roundeven( arg )

(since C23)

# Parameters

# Return value

If no errors occur, the nearest integer value to arg, rounding halfway cases to nearest even integer, is returned.

# Example

#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));
}

# See also