fsqrt
-
-
önemli edit:
"doh. this method (newton-rhapson) has been used for years, and the theory behind it is hundreds of years old. it's a damn shame if people begin to call it carmack's sqrt now, just because carmack has a guru's status and a cool sounding name.
- mikko kauppila (whose name doesn't sound cool"
--
intel işlemcilerde çalıştırıldığında john carmack'in q_sqrt'undan dört kat daha yavaş olan instruction. diğer işlemcilerde pek hız farkı olmayabilir.
quake 3'ün kodundan aşırdığım fonksiyonu da yazayım da tam olsun:
float q_rsqrt( float number )
{
long i;
float x2, y;
const float threehalfs = 1.5f;
x2 = number * 0.5f;
y = number;
i = * ( long * ) &y; // evil floating point bit level hacking
i = 0x5f3759df - ( i >> 1 ); // what the fuck?
y = * ( float * ) &i;
y = y * ( threehalfs - ( x2 * y * y ) ); // 1st iteration
// y = y * ( threehalfs - ( x2 * y * y ) ); // 2nd iteration, this can be removed
#ifndef q3_vm
#ifdef __linux__
assert( !isnan(y) ); // bk010122 - fpe?
#endif
#endif
return y;
}
aylar yıllar sonra gelen edit: http://www.beyond3d.com/content/articles/8/
-----original message-----
from: john carmack
sent: 26 april 2004 19:51
subject: re: origin of fast approximated inverse square root
at 06:38 pm 4/26/2004 +0100, you wrote:
>hi john,
>
>there's a discussion on beyond3d.com's forums about who the author of
>the following is:
>
>float invsqrt (float x){
> float xhalf = 0.5f*x;
> int i = *(int*)&x;
> i = 0x5f3759df - (i>>1);
> x = *(float*)&i;
> x = x*(1.5f - xhalf*x*x);
> return x;
>}
>
>is that something we can attribute to you? analysis shows it to be
>extremely clever in its method and supposedly from the q3 source.
>most people say it's your work, a few say it's michael abrash's. do
>you know who's responsible, possibly with a history of sorts?
not me, and i don't think it is michael. terje matheson perhaps?
john carmack
ekşi sözlük kullanıcılarıyla mesajlaşmak ve yazdıkları entry'leri
takip etmek için giriş yapmalısın.
hesabın var mı? giriş yap