C++ round和numpy round区别

先来看numpy round:
numpy round reference
For values exactly halfway between rounded decimal values, NumPy rounds to the nearest even value. Thus 1.5 and 2.5 round to 2.0, -0.5 and 0.5 round to 0.0, etc.
可以看到, numpy的round是四舍五入到最近的偶数
c++ round reference

value | round | floor ceil | trunc
------- | -------- | -------- | ------- | --------
2.3 | 2.0 | 2.0 | 3.0 | 2.0
3.8 | 4.0 | 3.0 | 4.0 | 3.0
5.5 | 6.0 | 5.0 | 6.0 | 5.0
-2.3 | -2.0 | -3.0 | -2.0 | -2.0
-3.8 | -4.0 | -4.0 | -3.0 | -3.0
-5.5 | -6.0 | -6.0 | -5.0 | -5.0

看起来c++的操作是不管符号是啥, 统统四舍五入

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容