Need help in translating code from C to Java.
Posted
by Vuntic
on Stack Overflow
See other posts from Stack Overflow
or by Vuntic
Published on 2010-05-11T14:41:46Z
Indexed on
2010/05/11
21:14 UTC
Read the original article
Hit count: 239
From this article. Here's the code:
float InvSqrt(float x){ // line 0
float xhalf = 0.5f * x;
int i = *(int*)&x; // store floating-point bits in integer
i = 0x5f3759d5 - (i >> 1); // initial guess for Newton's method
x = *(float*)&i; // convert new bits into float
x = x*(1.5f - xhalf*x*x); // One round of Newton's method
return x;
}
...I can't even tell if that's C or C++. [okay apparently it's C, thanks] Could someone translate it to Java for me, please? It's (only, I hope) lines 2 and 4 that are confusing me.
© Stack Overflow or respective owner