官方文档藏得比较深,用来备忘
文档:https://docs.nvidia.com/cuda/cuda-math-api/group__CUDA__MATH__INTRINSIC__CAST.html#group__CUDA__MATH__INTRINSIC__CAST
1. rd 向下舍入,向负无穷截断,等价于C/C++中floor()
__device__ float __float2int_rd ( float x )
__float2int_rd(9.6f) = 9
__float2int_rd(-9.3f) = -10
2. ru 向上舍入,向正无穷截断,等价于C/C++中ceil()
__device__ float __float2int_ru ( float x )
__float2int_ru(9.3f) = 10
__float2int_ru(-9.6f) = -9
3. rz 向零截断,等价于C/C++中trunc()
// rz 向零截断,等价于C中floor()
__device__ float __float2int_rz ( float x )
__float2int_rz(9.6f) = 9
__float2int_rz(-9.3f) = -9
4. rn 四舍六入五取偶,注意不是四舍五入,等价于C/C++中rint()
// rn 最近整数
__device__ float __float2int_rn ( float x )
__float2int_rn(9.3f) = 9
__float2int_rn(9.5f) = 10
__float2int_rn(10.5f) = 10
__float2int_rn(11.5f) = 12
__float2int_rn(-9.3f) = -9
【备注】C/C++ round 四舍五入,遇到五且朝向绝对值大的舍入
参考:https://bbs.gpuworld.cn/index.php?topic=73335.0