OK...Deus wrote:While we are at it do this in Java

http://betterexplained.com/articles/und ... uare-root/

Code: Select all

```
public static float InvSqrt(float x){
float xhalf = 0.5f * x;
int i = Float.floatToIntBits(x);
i = 0x5f3759d5 - (i >> 1); // initial guess for Newton's method
x = Float.intBitsToFloat(i); // convert new bits into float
x = x*(1.5f - xhalf*x*x); // One round of Newton's method
return x;
}
```

I just used the same methodDeus wrote:Well this takes a couple of clock cycles but in C++ but HUNDREDS in Java (because you cannot use the same method)

See above.Deus wrote:But you dont do b= a / sqrt(x^2+y^2+z^2) in raytracers so this optimization is not relevant right?

Firstly, you were a bit naive to think the same optimisation isn't possible in Java. Secondly, you were even more naive to think that an approximation like this has any use in a ray tracer so yes, it is totally irrelevant

Ian.