Condividi tramite


lround, lroundf, lroundl, llround, llroundf, llroundl

Arrotonda un valore in virgola mobile all'integer più vicino.

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

Parametri

  • x
    Il valore a virgola mobile da arrotondare.

Valore restituito

Le funzioni llround e lround restituiscono il valore integer long o long long più vicino a x. I valori a metà vengono arrotondati per eccesso, indipendentemente dall'impostazione della modalità di arrotondamento della virgola mobile. Nessun ritorno di errore.

Input

Eccezione SEH

Eccezione Matherr

± QNAN, IND

nessuno

_DOMAIN

Note

Poiché C++ consente l'overload, è possibile chiamare gli overload di lround o llround che accettano e restituiscono i valori float e long double. In un programma C, lround e llround vengono sempre accettati e restituiscono double.

Requisiti

Routine

Intestazione obbligatoria

lround, lroundf, lroundl, llround, llroundf, llroundl

<math.h>

Per ulteriori informazioni sulla compatibilità, vedere Compatibilità.

Esempio

// crt_lround.c
// Build with: cl /W3 /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.5;

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

Equivalente .NET Framework

System::Math::Round

Vedere anche

Riferimenti

Supporto a virgola mobile

ceil, ceilf, ceill

floor, floorf, floorl

fmod, fmodf

round, roundf, roundl

rint, rintf, rintl

Altre risorse

lrint, lrintf, lrintl, llrint, llrintf, llrintl

nearbyint, nearbyintf, nearbyintl