lround, lroundf, lroundl, llround, llroundf, llroundl

Zaokrągla wartość zmiennoprzecinkową do najbliższej liczby całkowitej.

Składnia

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

Parametry

x
Wartość zmiennoprzecinkowa do zaokrąglonej.

Wartość zwracana

Funkcje lround i llround zwracają najbliższą long lub long long całkowitą liczbę całkowitą do x. Wartości w połowie są zaokrąglane od zera, niezależnie od ustawienia trybu zaokrąglania zmiennoprzecinkowego. Nie ma zwracanego błędu.

Dane wejściowe Wyjątek SEH Wyjątek _matherr
± QNaN, IND Brak _DOMAIN

Uwagi

Ponieważ język C++ umożliwia przeciążenie, można wywołać lround lub llround przeciążenia, które przyjmują i zwracają wartości i .floatlong double W programie języka C, chyba że używasz makra <tgmath.h> do wywołania tej funkcji, lround i llround zawsze pobieraj i zwracaj doubleelement .

Jeśli używasz makra <tgmath.h>lround() , typ argumentu określa, która wersja funkcji jest zaznaczona. Aby uzyskać szczegółowe informacje, zobacz Typy ogólne matematyczne .

Domyślnie stan globalny tej funkcji jest zakresem aplikacji. Aby zmienić to zachowanie, zobacz Stan globalny w CRT.

Wymagania

Procedura Wymagany nagłówek
lround, lroundf, lroundl, llround, llroundf, llroundl <math.h>
lround Makro <tgmath.h>

Aby uzyskać więcej informacji o zgodności, zobacz Zgodność.

Przykład

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

Zobacz też

Obsługa obliczeń matematycznych i zmiennoprzecinkowych
ceil, ceilf, ceill
floor, floorf, floorl
fmod, fmodf
lrint, lrintf, lrintl, llrint, llrintf, llrintl
round, roundf, roundl
nearbyint, nearbyintf, nearbyintl
rint, rintf, rintl