Partilhar via


lround, lroundf, lroundl, llround, llroundf, , llroundl

Arredonda um valor de ponto flutuante para o inteiro mais próximo.

Sintaxe

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
O valor do ponto flutuante a ser arredondado.

Valor retornado

As funções lround e llround retornam o inteiro long ou long long mais próximo de x. Valores decimais são arredondados para cima, independentemente da configuração do modo de arredondamento de ponto flutuante. Não há retorno de erro.

Entrada Exceção SEH Exceção _matherr
± QNaN, IND nenhum _DOMAIN

Comentários

Como o C++ permite sobrecarga, você pode chamar lround ou llround sobrecarregar que recebem e retornam float valores e long double . Em um programa C, a menos que você esteja usando a <macro tgmath.h> para chamar essa função, lround sempre llround pegue e retorne um double.

Se você usa a macro <tgmath.h>lround(), o tipo do argumento determina qual versão da função será selecionada. Confira Matemática do tipo genérico para obter detalhes.

Por padrão, o estado global dessa função tem como escopo o aplicativo. Para alterar esse comportamento, confira Estado global no CRT.

Requisitos

Rotina Cabeçalho necessário
lround, lroundf, lroundl, llround, llroundf, , llroundl <math.h>
Macro lround <tgmath.h>

Para obter informações sobre compatibilidade, consulte Compatibilidade.

Exemplo

// 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

Confira também

Suporte matemático e de ponto flutuante
ceil, ceilf, ceill
floor, floorf, floorl
fmod, fmodf
lrint, lrintf, lrintl, llrint, llrintf, , llrintl
round, roundf, roundl
nearbyint, nearbyintf, nearbyintl
rint, rintf, rintl