[Home]FastMath/SquareRoot

Robo Home | FastMath | Changes | Preferences | AllPages

Showing revision 5
From http://www-106.ibm.com/developerworks/library/wi-elite17.html?ca=dnt-435

    // very fast square root approximation
    public final static int sqrt( long val ) {
        long temp, g = 0, b = 0x8000, bshft = 15;
        do {
            if( val >= ( temp = ( ( ( g << 1 ) + b ) << bshft-- ) ) ) {
                g += b;
                val -= temp;
            }
        } while( ( b >>= 1 ) > 0 );
        return (int)g;
    }

Hang on... that casts the answer into an int. That's a little TOO approximate for my liking. -- Tango

It's also about 10 times slower than Math.sqrt() on my machine... Maybe this whole idea was bad. :-p --David Alves

I think a lot of these functions are implemented in hardware, so making interpreted software variants may not help. -- Kawigi


Robo Home | FastMath | Changes | Preferences | AllPages
Edit revision 5 of this page | View other revisions | View current revision
Edited February 19, 2004 22:52 EST by Kawigi (diff)
Search: