Bagikan melalui


lround, lroundf, lroundl, llround, llroundf, llroundl

Membulatkan nilai floating-point ke bilangan bulat terdekat.

Sintaks

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

Parameter

x
Nilai floating-point untuk dibulatkan.

Nilai hasil

Fungsi lround dan llround mengembalikan bilangan bulat atau terdekat long longlong ke x. Nilai setengah dibulatkan jauh dari nol, terlepas dari pengaturan mode pembulatan floating-point. Tidak ada pengembalian kesalahan.

Input Pengecualian SEH Pengecualian _matherr
± QNaN, IND tidak ada _DOMAIN

Keterangan

Karena C++ memungkinkan kelebihan beban, Anda dapat memanggil lround atau llround kelebihan beban yang mengambil dan mengembalikan float nilai long double . Dalam program C, kecuali Anda menggunakan <makro tgmath.h> untuk memanggil fungsi ini, lround dan llround selalu mengambil dan mengembalikan double.

Jika Anda menggunakan <makro tgmath.h>lround() , jenis argumen menentukan versi fungsi mana yang dipilih. Lihat Matematika generik jenis untuk detailnya.

Secara default, status global fungsi ini dicakup ke aplikasi. Untuk mengubah perilaku ini, lihat Status global di CRT.

Persyaratan

Rutin Header yang diperlukan
lround, lroundf, lroundl, llround, llroundf, llroundl <matematika.h>
lround makro <tgmath.h>

Untuk informasi kompatibilitas selengkapnya, lihat Kompatibilitas.

Contoh

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

Baca juga

Dukungan matematika dan titik mengambang
ceil, ceilf, ceill
floor, floorf, floorl
fmod, fmodf
lrint, lrintf, lrintl, llrint, llrintf, llrintl
round, roundf, roundl
nearbyint, nearbyintf, nearbyintl
rint, rintf, rintl