小编Ran*_*dom的帖子

在 C++ 中将 float 转换为 int 的最快方法

在 C++ 中将浮点数转换为整数(向零舍入)的最快且最有效的方法是什么?是吗

long ftoint(float x)
{
    unsigned int e = (0x7F + 31) - ((* (unsigned int*) &x & 0x7F800000) >> 23);
    unsigned int m = 0x80000000 | (* (unsigned int*) &x << 8);
    return int((m >> e) & -(e < 32));
}
Run Code Online (Sandbox Code Playgroud)

c++ performance type-conversion

0
推荐指数
1
解决办法
859
查看次数

标签 统计

c++ ×1

performance ×1

type-conversion ×1