Aracılığıyla paylaş


lround, lroundf, lroundl, llround, llroundf, llroundl

Kayan nokta değerini en yakın tamsayıya yuvarlar.

Sözdizimi

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

Parametreler

x
Yuvarlanacak kayan nokta değeri.

Dönüş değeri

lround ve llround işlevleri, öğesine en long yakın veya long long tamsayıyı xdöndürür. Yarım değerler, kayan nokta yuvarlama modunun ayarından bağımsız olarak sıfırdan uzağa yuvarlanır. Hata döndürme yok.

Girdi SEH özel durumu _matherr özel durumu
± QNaN, IND yok _DOMAIN

Açıklamalar

C++ aşırı yüklemeye izin verdiğinden, alıp döndüren long doublefloat ve değerleri döndüren çağrıları veya llround aşırı yüklemeleri çağırabilirsinizlround. C programında, bu işlevi llroundlround çağırmak için tgmath.h> makrosunu <kullanmadığınız ve her zaman bir doublealıp döndürmediğiniz sürece.

tgmath.h>lround() makroyu <kullanırsanız, işlevin hangi sürümünün seçili olduğunu bağımsız değişkenin türü belirler. Ayrıntılar için bkz . Tür genel matematik .

Varsayılan olarak, bu işlevin genel durumunun kapsamı uygulama olarak belirlenmiştir. Bu davranışı değiştirmek için bkz. CRT'de Genel durum.

Gereksinimler

Yordam Gerekli başlık
lround, lroundf, lroundl, llround, llroundf, llroundl <math.h>
lround Makro <tgmath.h>

Daha fazla uyumluluk bilgisi için bkz . Uyumluluk.

Örnek

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

Ayrıca bkz.

Matematik ve kayan nokta desteği
ceil, ceilf, ceill
floor, floorf, floorl
fmod, fmodf
lrint, lrintf, lrintl, llrint, llrintf, llrintl
round, roundf, roundl
nearbyint, nearbyintf, nearbyintl
rint, rintf, rintl