C99 | long int lround (double x);
long int lroundf (float x); long int lroundl (long double x); |
C++11 | long int lround (double x);
long int lround (float x); long int lround (long double x); long int lround (T x); // additional overloads for integral types |
C99 | 头文件<tgmath.h> 提供了该函数的类型泛型宏版本。 |
C++11 | 这个头文件(<cmath>)为整型提供了额外的重载:
这些重载有效地在计算之前将x转换为double(在T是任何整型时定义)。
|
/* lround example */ #include <stdio.h> /* printf */ #include <math.h> /* lround */ int main () { printf ( "lround (2.3) = %ld\n", lround(2.3) ); printf ( "lround (3.8) = %ld\n", lround(3.8) ); printf ( "lround (-2.3) = %ld\n", lround(-2.3) ); printf ( "lround (-3.8) = %ld\n", lround(-3.8) ); return 0; } |
Rounding using to-nearest rounding: lround (2.3) = 2 lround (3.8) = 4 lround (-2.3) = -2 lround (-3.8) = -4 |
ceil | 向上舍入(function ) |
floor | 向下舍入(function ) |
trunc | 截断(function ) |
lrint | 舍入并强制转换为长整数(function ) |
nearbyint | 舍入到最近的整数值(function ) |
round | 就近舍入(function ) |
llround | 舍入到最接近的值并转换为 long long integer(function ) |