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
);

参数

  • x
    要舍入的浮点值。

返回值

lroundllround 函数将最近的 long 或 long long 整数返回到 x。 无论浮点舍入模式的设置如何,中间的值都远离零舍入。 无错误返回。

输入

SEH 异常

Matherr 异常

± QNAN, IND

_DOMAIN

备注

由于 C++ 允许重载,您可以调用 lroundllround 的重载,该重载采用和返回 float 和 long double 值。 在 C 程序中,lroundllround 始终采用并返回 double。

要求

例程

必需的标头

lround, lroundf, lroundl, llround, llroundf, llroundl

<math.h>

有关其他兼容性信息,请参见兼容性

示例

// crt_lround.c
// Build with: cl /W3 /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.5;

   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));
}
  

.NET Framework 等效项

System::Math::Round

请参见

参考

浮点支持

ceil、ceilf、ceill

floor、floorf、floorl

fmod、fmodf

round、roundf、roundl

rint, rintf, rintl

其他资源

lrint、lrintf、lrintl、llrint、llrintf、llrintl

nearbyint、nearbyintf、nearbyintl