Compartilhar via


rint, rintf, rintl

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

double rint( double x );
float rint( float x );  // C++ only
long double rint( long double x );  // C++ only
float rintf( float x ); 
long double rintl( long double x ); 

Parâmetros

  • x
    O valor do ponto flutuante a ser arredondado.

Valor de retorno

As funções rint retornam um valor de ponto flutuante que representa o inteiro mais próximo a x. Valores decimais são arredondados de acordo com a configuração atual do modo de arredondamento do ponto flutuante, assim como as funções nearbyint. Diferentemente das funções nearbyint, as funções rint podem resultar na exceção de ponto flutuante FE_INEXACT se o resultado tiver um valor diferente do argumento. Nenhum erro é retornado.

Entrada

Exceção SEH

Exceção _matherr

± ∞, QNAN, IND

nenhum

nenhum

Denormals

EXCEPTION_FLT_UNDERFLOW

nenhum

Comentários

Como C++ permite sobrecargas, é possível chamar sobrecargas de rint que tomam e retornam valores de float e long double. Em um programa C, rint sempre toma e retorna um double.

Requisitos

Função

Cabeçalho C

Cabeçalho C++

rint, rintf, rintl

<math.h>

<cmath>

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

Exemplo

// crt_rint.c
// Build with: cl /W3 /Tc crt_rint.c
// This example displays the rounded results of
// the floating-point values 2.499999, -2.499999, 
// 2.8, -2.8, 2.5 and -2.5.

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

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

   printf("rint(%f) is %.0f\n", x, rint (x));
   printf("rint(%f) is %.0f\n", -x, rint (-x));
   printf("rintf(%f) is %.0f\n", y, rintf(y));
   printf("rintf(%f) is %.0f\n", -y, rintf(-y));
   printf("rintl(%Lf) is %.0Lf\n", z, rintl(z));
   printf("rintl(%Lf) is %.0Lf\n", -z, rintl(-z));
}
            
          

Equivalência do .NET Framework

System::Math::round

Consulte também

Referência

Suporte de ponto flutuante

ceil, ceilf, ceill

floor, floorf, floorl

fmod, fmodf

lround, lroundf, lroundl, llround, llroundf, llroundl

rint, rintf, rintl

Outros recursos

lrint, lrintf, lrintl, llrint, llrintf, llrintl

nearbyint, nearbyintf, nearbyintl