Not
Bu sayfaya erişim yetkilendirme gerektiriyor. Oturum açmayı veya dizinleri değiştirmeyi deneyebilirsiniz.
Bu sayfaya erişim yetkilendirme gerektiriyor. Dizinleri değiştirmeyi deneyebilirsiniz.
Kayan nokta değerini en yakın tamsayı değerine yuvarlar.
Sözdizimi
double round(
double x
);
float round(
float x
); // C++ only
long double round(
long double x
); // C++ only
float roundf(
float x
);
long double roundl(
long double x
);
#define round(X) // Requires C11 or later
Parametreler
x
Yuvarlanacak kayan nokta değeri.
Dönüş değeri
İşlevler, round
öğesine en yakın tamsayıyı x
temsil eden bir kayan nokta değeri dö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.
Giriş | SEH özel durumu | _matherr özel durumu |
---|---|---|
± QNaN, IND | yok | _DOMAIN |
Açıklamalar
C++ aşırı yüklemeye izin verdiğinden, bu alma ve döndürme float
ile long double
değerlerinin round
aşırı yüklemelerini çağırabilirsiniz. C programında, bu işlevi çağırmak için makroyu <tgmath.h>
kullanmıyorsanız, round
her zaman bir double
alır ve döndürür.
öğesinden round
<tgmath.h>
makro 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 |
---|---|
round , roundf , roundl |
<math.h> |
round Makro |
<tgmath.h> |
Daha fazla uyumluluk bilgisi için bkz . Uyumluluk.
Örnek
// Build with: cl /W3 /Tc
// This example displays the rounded
// results of floating-point values
#include <math.h>
#include <stdio.h>
int main()
{
printf("===== Round a float\n\n");
float floatValue = 2.4999999f; // float stores a value close to, but not exactly equal to, the initializer below. floatValue will contain 2.5 because it is the closest single precision value
printf("roundf(%.1000g) is %.1000g\n", floatValue, roundf(floatValue));
printf("roundf(%.1000g) is %.1000g\n", -floatValue, roundf(-floatValue));
// double stores a value close to, but not exactly equal to, the initializer below. The closest double value is just slightly larger.
double doubleValue = 2.4999999;
printf("\n===== Round a double\n\n");
printf("round(%.1000g) is %.1000g\n", doubleValue, round(doubleValue));
printf("round(%.1000g) is %.1000g\n", -doubleValue, round(-doubleValue));
// long double stores a value close to, but not exactly equal to, the initializer below. The closest long double value is just slightly larger.
long double longDoubleValue = 2.4999999L;
printf("\n===== Round a long double\n\n");
printf("roundl(%.1000g) is %.1000g\n", longDoubleValue, roundl(longDoubleValue));
printf("roundl(%.1000g) is %.1000g\n", -longDoubleValue, roundl(-longDoubleValue));
return 0;
}
===== Round a float
roundf(2.5) is 3
roundf(-2.5) is -3
===== Round a double
round(2.499999900000000163657887242152355611324310302734375) is 2
round(-2.499999900000000163657887242152355611324310302734375) is -2
===== Round a long double
roundl(2.499999900000000163657887242152355611324310302734375) is 2
roundl(-2.499999900000000163657887242152355611324310302734375) is -2
Ayrıca bkz.
Matematik ve kayan nokta desteği
ceil
, ceilf
, ceill
floor
, floorf
, floorl
fmod
, fmodf
lrint
, lrintf
, lrintl
, , llrint
, llrintf
, llrintl
lround
, lroundf
, lroundl
, , llround
, llroundf
, llroundl
nearbyint
, nearbyintf
, nearbyintl
rint
, rintf
, rintl