快速平方根算法
Carmack在QUAKE3中使用了下面的算法,它第一次在公众场合出现的时候,几乎震住了所有的人。据说该算法其实并不是Carmack发明的,它真正的作者是Nvidia的Gary Tarolli(未经证实)。
今天看到一个快速平方根算法,很是巧妙。据称是Carmack在QUAKE3中使用了下面的算法,它第一次在公众场合出现的时候,几乎震住了所有的人。
float InvSqrt(float x)
{
float xhalf = 0.5f*x;
int i = *(int*)&x; // get bits for floating value
i = 0x5f3759df - (i>>1); // gives initial guess y0
x = *(float*)&i; // convert bits back to float
x = x*(1.5f-xhalf*x*x); // Newton step, repeating increases accuracy
return x;
}
Chris Lomont写了篇论文,关于这个算法:
http://www.lomont.org/Math/Papers/2003/InvSqrt.pdf




Dear Matthew: I’ve got what seems like a good idea for some nursing home comedy. They would love having a handsome young man — you — come in to make them laugh. They pay, too. Last year, I broke my leg and had to stay in an NH for 2 months. The laughs were few and far between, but they did bring in a comedy duo one evening [from Atlanta, of course] who made most of us laugh. Some didn’t get the jokes. They thought it was bingo nite. You know, the ones with their eyes closed and their mouths hanging open. The orderlies rolled gurneys out, face covered over, almost every night.
Talked to Mary McPharr yesterday. That’s why I found your website. I’m still looking for the standup vs. improv, which she says is a “riot.” That’s the way we used to talk. Love, Mary