Subject: Re: fsqrt

From: Benjamin Herrenschmidt <[email-masked]>
Date: Fri, 07 Jun 2013 18:59:17 +1000

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.