先来看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 |
3.8 | 4.0 | 3.0 | 4.0 |
5.5 | 6.0 | 5.0 | 6.0 |
-2.3 | -2.0 | -3.0 | -2.0 |
-3.8 | -4.0 | -4.0 | -3.0 |
-5.5 | -6.0 | -6.0 | -5.0 |
看起来c++的操作是不管符号是啥, 统统四舍五入