在 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)
?