快速平方根倒数

//卡马克(quake3作者) 0x5f3759df
//普渡大学的数学家Chris Lomont 0x5f375a86

static float invSqrt(float number)
{
    volatile long i;
    volatile float x,y;
    volatile const float f = 1.5f;
    x = number * 0.5F;
    y = number;
    i = * (( long * ) &y);
    i = 0x5f375a86 - ( i >> 1 );
    y = * (( float * ) & i);
    y = y * ( f - ( x * y * y ) );
    return y;
}

更多可以看

1、Quake 3 Arena v1.32中q_math.c 链接https://sourceforge.net/projects/quake3/files/quake3/quake3-1.32b/

2、《Fast Inverse Square Root》 链接http://www.matrix67.com/data/InvSqrt.pdf

3、链接https://en.wikipedia.org/wiki/Fast_inverse_square_root

原文地址:https://www.cnblogs.com/libra13179/p/5969128.html