File talk:Invsqrt0-10000.svg

来自Wikimedia Commons
跳转到导航 跳转到搜索

The code of the program used to create the data:

#include <math.h>
#include <stdio.h>


float InvSqrt (float x)
{
    float xhalf = 0.5f*x;
    int i = *(int*)&x;
    i = 0x5f3759df - (i>>1);
    x = *(float*)&i;
    return x*(1.5f - xhalf*x*x);
}

int main()
{
    float f;

    for( f=0.01f;f<=10000.f;f*=1.01 )
    {
	printf("%f\t%f\t%f\t%f\n", f, InvSqrt(f), 1.f/sqrt(f), -(InvSqrt(f)-1.f/sqrt(f)));
    }
    return 0;
}