fsqrt

Benjamin Herrenschmidt benh at kernel.crashing.org
Fri Jun 7 18:59:17 EST 2013


On Fri, 2013-06-07 at 18:53 +1000, Benjamin Herrenschmidt wrote:

> +
> +static double crackpot_sqrt(double val)
> +{
> +    int i;
> +    float x, y;
> +    const float f = 1.5F;
> +
> +    x = val * 0.5F;
> +    y  = val;
> +    i  = * ( int * ) &y;
> +    i  = 0x5f3759df - ( i >> 1 );
> +    y  = * ( float * ) &i;
> +    y  = y * ( f - ( x * y * y ) );
> +    y  = y * ( f - ( x * y * y ) );
> +    return val * y;
> +}
> +

For those interested, this is the Quake3 sqrt from Carmack ... there's
plenty of literature about it one or two google clicks away :-)

Cheers,
Ben.




More information about the Linuxppc-dev mailing list