Compartir a través de


lround, lroundf, lroundl, llround, llroundf, llroundl

Redondea un valor de punto flotante al entero más cercano.

Sintaxis

long lround(
   double x
);
long lround(
   float x
);  // C++ only
long lround(
   long double x
);  // C++ only
long lroundf(
   float x
);
long lroundl(
   long double x
);
long long llround(
   double x
);
long long llround(
   float x
);  // C++ only
long long llround(
   long double x
);  // C++ only
long long llroundf(
   float x
);
long long llroundl(
   long double x
);
#define lround(X) // Requires C11 or higher

Parámetros

x
Valor de punto flotante que se va a redondear.

Valor devuelto

Las funciones lround y llround devuelven el entero long o long long más próximo a x. Los valores que se encuentran a medio camino se redondean en cero, independientemente de la configuración del modo de redondeo del punto flotante. No se devuelve ningún error.

Entrada Excepción SEH Excepción de _matherr
± QNaN, IND None _DOMAIN

Comentarios

Dado que C++ permite sobrecargar, puede llamar a lround o llround sobrecargas que toman y devuelven float y long double valores. En un programa de C, a menos que use la <macro tgmath.h> para llamar a esta función y lroundllround tome y devuelva siempre un double.

Si usa la macro <tgmath.h>lround(), el tipo del argumento determina qué versión de la función se selecciona. Consulte Matemáticas de tipo genérico para obtener más información.

De manera predeterminada, el estado global de esta función está limitado a la aplicación. Para cambiar este comportamiento, consulte Estado global en CRT.

Requisitos

Routine Encabezado necesario
lround, lroundf, lroundl, llround, llroundf, llroundl <math.h>
lroundMacro <tgmath.h>

Para obtener más información sobre compatibilidad, consulte Compatibilidad.

Ejemplo

// crt_lround.c
// Build with: cl /W4 /Tc crt_lround.c
// This example displays the rounded results of
// the floating-point values 2.499999, -2.499999,
// 2.8, -2.8, 3.5 and -3.5.

#include <math.h>
#include <stdio.h>

int main( void )
{
   double x = 2.499999;
   float y = 2.8f;
   long double z = 3.5L;

   printf("lround(%f) is %d\n", x, lround(x));
   printf("lround(%f) is %d\n", -x, lround(-x));
   printf("lroundf(%f) is %d\n", y, lroundf(y));
   printf("lroundf(%f) is %d\n", -y, lroundf(-y));
   printf("lroundl(%Lf) is %d\n", z, lroundl(z));
   printf("lroundl(%Lf) is %d\n", -z, lroundl(-z));
}
lround(2.499999) is 2
lround(-2.499999) is -2
lroundf(2.800000) is 3
lroundf(-2.800000) is -3
lroundl(3.500000) is 4
lroundl(-3.500000) is -4

Consulte también

Compatibilidad con matemáticas y punto flotante
ceil, ceilf, ceill
floor, floorf, floorl
fmod, fmodf
lrint, lrintf, lrintl, llrint, llrintf, llrintl
round, roundf, roundl
nearbyint, nearbyintf, nearbyintl
rint, rintf, rintl