查了下man round
The round functions will return a rounded integer in the specified format that will be rounded to the nearest integer regardless of the current rounding mode.
会向最近的整数舍入,但是没有提.5离左右的两个整数距离一样时如何舍入。
查了下gcc的文档:
Without any explicit options, GCC assumes round to nearest or even and does not care about signalling NaNs. Compare with C99's #pragma STDC FENV ACCESS OFF。
意思是向偶数方向舍入。但是如下代码,测试结果表明,都是进行了四舍五入。
请问这是怎么回事,谢谢;)
printf("0.5 %f\n", round(0.5));
printf("1.5 %f\n", round(1.5));
printf("2.5 %f\n", round(2.5));
printf("3.5 %f\n", round(3.5));
printf("4.5 %f\n", round(4.5));
printf("5.5 %f\n", round(5.5));
printf("6.5 %f\n", round(6.5));
printf("7.5 %f\n", round(7.5));
printf("8.5 %f\n", round(8.5));
printf("9.5 %f\n", round(9.5));