lround, lroundf, lroundl, llround, llroundf, llroundl

부동 소수점 값을 가장 가까운 정수로 반올림합니다.

구문

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

매개 변수

x
반올림할 부동 소수점 값입니다.

반환 값

lroundllround 함수는 x에 가장 가까운 long 또는 long long 정수를 반환합니다. 중간값은 부동 소수점 반올림 모드의 설정에 관계없이 0에서 멀어지는 쪽으로 반올림됩니다. 오류 반환이 없습니다.

입력 SEH 예외 _matherr 예외
± QNaN, IND 없음 _DOMAIN

설명

C++는 오버로드를 허용하므로 값을 가져와서 반환 floatlong double 하는 오버로드를 호출 lround 하거나 llround 오버로드할 수 있습니다. C 프로그램에서는 tgmath.h 매크로를 <사용하여 이 함수를 호출하고 llround 항상 해당 함수 lround 를 가져와서 반환하지 않는 한double.>

tgmath.h>lround() 매크로를 <사용하는 경우 인수 형식에 따라 선택한 함수 버전이 결정됩니다. 자세한 내용은 형식 제네릭 수학을 참조하세요.

기본적으로 이 함수의 전역 상태는 애플리케이션으로 범위가 지정됩니다. 이 동작을 변경하려면 CRT의 전역 상태를 참조하세요.

요구 사항

루틴에서 반환된 값 필수 헤더
lround, lroundf, lroundl, llround, llroundf, llroundl <math.h>
lround 매크로 <tgmath.h>

호환성에 대한 자세한 내용은 호환성을 참조하세요.

예시

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

참고 항목

수학 및 부동 소수점 지원
ceil, ceilf, ceill
floor, floorf, floorl
fmod, fmodf
lrint, lrintf, lrintl, llrint, llrintf, llrintl
round, roundf, roundl
nearbyint, nearbyintf, nearbyintl
rint, rintf, rintl