平方根运算其实迭代没用,速度是编译器自带的sqrt的4倍。一切都来自一个不知道从哪里冒出来的常数0x5f3759df。关注whatthefuckfloatq _ r SQRT(浮点数){ longifloatx2,y;constfloatthreehalfs = 1.5Fx2 =数量* 0.5Fy =数字;i=*(long*)
开方运算居然没用迭代,速度是编译器自带的sqrt的四倍,一切源于一个不知从哪里来的常数0x5f3759df,注意后来者写的what the fuckfloat Q_rsqrt( float number ){long i;float x2, y;const float threehalfs = 1.5F;x2 = number * 0.5F;y = number;i = * ( long * )