lround, lroundf, lroundl, llround, llroundf, llroundl

Arrotonda un valore a virgola mobile all'intero più vicino.

Sintassi

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

Parametri

x
Valore a virgola mobile da arrotondare.

Valore restituito

Le funzioni lround e llround restituiscono l'intero long o long long più prossimo a x. Ai valori a metà viene applicato l'arrotondamento lontano da zero, indipendentemente dall'impostazione della modalità di arrotondamento a virgola mobile. Non viene restituito alcun errore.

Input Eccezione SEH Eccezione _matherr
± QNaN, IND Nessuno _DOMAIN

Osservazioni:

Poiché C++ consente l'overload, è possibile chiamare lround o llround overload che accettano e restituiscono float valori e long double . In un programma C, a meno che non si usi la <macro tgmath.h> per chiamare questa funzione lround e llround accettare e restituire sempre .double

Se si utilizza la <macro tgmath.h>lround() , il tipo dell'argomento determina quale versione della funzione è selezionata. Per informazioni dettagliate, vedere La matematica generica dei tipi.

Per impostazione predefinita, lo stato globale di questa funzione è limitato all'applicazione. Per modificare questo comportamento, vedere Stato globale in CRT.

Requisiti

Ciclo Intestazione obbligatoria
lround, lroundf, lroundl, llround, llroundf, llroundl <math.h>
lround Macro <tgmath.h>

Per altre informazioni sulla compatibilità, vedere Compatibility (Compatibilità).

Esempio

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

Vedi anche

Supporto matematico e a virgola mobile
ceil, ceilf, ceill
floor, floorf, floorl
fmod, fmodf
lrint, lrintf, lrintl, llrint, llrintf, llrintl
round, roundf, roundl
nearbyint, nearbyintf, nearbyintl
rint, rintf, rintl