< 2007年8月 >
2930311234
567891011
12131415161718
19202122232425
2627282930311
2345678

# Crytek

• crymod
• Crytek's Offical Modding Portal

# WOW Stuff

•

• 积分 - 800144
• 排名 - 16

## John Carmack密码：0x5f3759df

`/*================SquareRootFloat================*/float SquareRootFloat(float number) {    long i;    float x, y;    const float f = 1.5F;    x = number * 0.5F;    y  = number;    i  = * ( long * ) &y;    i  = 0x5f3759df - ( i >> 1 );	//注意这一行    y  = * ( float * ) &i;    y  = y * ( f - ( x * y * y ) );    y  = y * ( f - ( x * y * y ) );    return number * y;}`
0x5f3759df？ 这是个什么东西？ 学过数值分析就知道，算法里面求平方根一般采用的是无限逼近的方法，比如牛顿迭代法，抱歉当年我数值分析学的太烂，也讲不清楚。简单来说比如求5的平方根，选一个猜测值比如2，那么我们可以这么算
5/2 = 2.5; 2.5+2/2 = 2.25; 5/2.25 = xxx; 2.25+xxx/2 = xxxx ...

Lomont为此写下一篇论文，"Fast Inverse Square Root"

John Carmack， ID的无价之宝

posted on 2008-11-29 18:13 七星重剑 阅读(1754) 评论(3)  编辑 收藏 引用 所属分类: PL--c/c++Game GraphicsIDE -- visual c++

FeedBack:
# re: John Carmack密码：0x5f3759df 2008-12-01 10:49 蚂蚁终结者

# re: John Carmack密码：0x5f3759df 2012-05-11 00:13 WILLIAMDolores
Some time ago, I needed to buy a good house for my corporation but I did not earn enough cash and could not order anything. Thank heaven my mother suggested to try to take the personal loans from reliable creditors. Thus, I acted so and used to be satisfied with my short term loan.   回复  更多评论