Namespaces
Variants

roundeven, roundevenf, roundevenl

From cppreference.net
< c ‎ | numeric ‎ | math
Common mathematical functions
Functions
Basic operations
(C99)
(C99)
(C99)
(C99) (C99) (C99) (C23)
Maximum/minimum operations
Exponential functions
Power functions
Trigonometric and hyperbolic functions
Nearest integer floating-point
(C99) (C99) (C99)
roundeven
(C23)
(C99)

(C99) (C99) (C99)
(C23) (C23) (C23) (C23)
Floating-point manipulation
Narrowing operations
(C23)
(C23)
(C23)
(C23)
(C23)
(C23)
Quantum and quantum exponent
Decimal re-encoding functions
Total order and payload functions
Classification
Error and gamma functions
(C99)
(C99)
(C99)
(C99)
Types
Macro constants
Special floating-point values
Arguments and return values
Error handling
Fast operation indicators
Definido en el encabezado <math.h>
float roundevenf ( float arg ) ;
(1) (desde C23)
double roundeven ( double arg ) ;
(2) (desde C23)
long double roundevenl ( long double arg ) ;
(3) (desde C23)
Definido en el encabezado <tgmath.h>
#define roundeven( arg )
(4) (desde C23)
1-3) Calcula el valor entero más cercano a arg (en formato de punto flotante), redondeando los casos intermedios al entero par más cercano, independientemente del modo de redondeo actual.
4) Macro genérico de tipos: Si arg tiene tipo long double , roundevenl es llamado. De lo contrario, si arg tiene tipo entero o el tipo double , roundeven es llamado. De lo contrario, roundevenf es llamado, respectivamente.

Contenidos

Parámetros

arg - valor de punto flotante

Valor de retorno

Si no ocurren errores, se devuelve el valor entero más cercano a arg , redondeando los casos intermedios al entero par más cercano.

Manejo de errores

Esta función no está sujeta a ninguno de los errores especificados en math_errhandling .

Si la implementación soporta aritmética de punto flotante IEEE (IEC 60559):

  • FE_INEXACT nunca se activa.
  • Si arg es ±∞, se devuelve sin modificaciones.
  • Si arg es ±0, se devuelve sin modificaciones.
  • Si arg es NaN, se devuelve NaN.

Ejemplo

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

Salida posible:

roundeven(+2.4) = +2.0
roundeven(-2.4) = -2.0
roundeven(+2.5) = +2.0
roundeven(-2.5) = -2.0
roundeven(+2.6) = +3.0
roundeven(-2.6) = -3.0
roundeven(+3.5) = +4.0
roundeven(-3.5) = -4.0
roundeven(-0.0) = -0.0
roundeven(-Inf) = -inf

Referencias

  • Estándar C23 (ISO/IEC 9899:2024):
  • 7.12.9.8 Las funciones roundeven (p: 265-266)
  • 7.27 Matemáticas genéricas de tipos <tgmath.h> (p: 386-390)
  • F.10.6.8 Las funciones roundeven (p: 532)

Véase también

(C99) (C99) (C99) (C99) (C99) (C99) (C99) (C99) (C99)
redondea a un entero usando el modo de redondeo actual con
excepción si el resultado difiere
(función)
(C99) (C99) (C99) (C99) (C99) (C99) (C99) (C99) (C99)
redondea al entero más cercano, redondeando lejos de cero en casos intermedios
(función)