So I do not know if this is useful or not and I really don't know if it is worth anything but I read about it on the nets and decided to take a whack at it and see what happens.
Basically, an algorithm that approximates the sqrt. I have no idea if I am doing this right but here it is
http://en.wikipedia.org/wiki/Alpha_max_plus_beta_min_algorithm 
love wiki
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| public float fastSqrt(Vector2f vec1) { float x = vec1.x*vec1.x; float y = vec1.y*vec1.y; if(x > y) { x = (x*.960434f)/vec1.x; y = (y*.397825f)/vec1.y; } else { y = (y*.960434f)/vec1.y; x = (x*.397825f)/vec1.x; } if(x <0) x *= -1; if(y <0) y *= -1; return x+y; } |
I know this is micro benchmarking which is basically useless but I found no speed improvement against Math.sqrt
I have to be doing something right as the result is only off from Math.sqrt by a little and in my particle prog there is almost no visual difference.
Anyone know something on this? I think it is a cool idea and would like to hear what other, more experienced, people have to say.