注册 | 登录

游侠NETSHOW论坛





游侠NETSHOW论坛 游侠NETSHOW论坛 游侠PC游戏综合讨论区 Quake-III代码里神奇的浮点开方函数
楼主: zpface
打印 上一主题 下一主题

[转贴] Quake-III代码里神奇的浮点开方函数 [复制链接]

帖子
258
精华
0
积分
129
金钱
372
荣誉
0
人气
0
评议
0
21#
发表于 2010-10-11 18:45:38 |只看该作者
原帖由 gunmanmax 于 2010-10-11 16:39 发表
呵呵,毕业设计搞的是quake1 引擎的portal算法,还没接触过quake3引擎
不过卡马克给出的那个数字真的是很有意思,难道数学真的是越复杂越明了吗?
我们这种还挣扎在微积分离散数学的人是无法理解的啊 ...

逼近理论大部分结论的原理都是Taylor展开啊,只是小部分需要一点代数和泛函知识。有微积分的知识基本足够了
惭愧快毕业了才知道这辈子最后悔的事:
选择了计算机专业而不是数学专业。
希望爱好计算机的学弟学妹参考!

使用道具 举报

帖子
336
精华
0
积分
168
金钱
261
荣誉
0
人气
0
评议
0
22#
发表于 2010-10-11 18:54:13 |只看该作者
现在早不打quake3了,改打ql了,据说ql的网络代码优化得更棒!
国内打ql的基本都集中在这里:
http://bbs.wasdcn.com/

使用道具 举报

帖子
8
精华
0
积分
4
金钱
88
荣誉
0
人气
0
评议
0
23#
发表于 2010-10-11 18:58:03 |只看该作者
天书,又见天书

使用道具 举报

no king rulus forever
浪漫神族 提卡斯芬得利
白银圣斗士·猎犬座
★★★★
安格里斯委员会【会长】

版主勋章大头像勋章

帖子
5122
精华
3
积分
4413
金钱
35910
荣誉
121
人气
408
评议
4
24#
发表于 2010-10-11 18:58:08 |只看该作者
又是论文帝??

使用道具 举报

硬件助理工程师

帖子
7345
精华
0
积分
3722
金钱
1121
荣誉
3
人气
50
评议
0
25#
发表于 2010-10-11 19:02:30 |只看该作者
微积分挂科的飘过

使用道具 举报

帖子
1760
精华
2
积分
1281
金钱
2364
荣誉
0
人气
0
评议
0
26#
发表于 2010-10-11 19:13:57 |只看该作者
[害怕] 高数常年崩溃的人~~~~~~~~
ηεεδ ξογ κτιι[/COLOR]
民主就是这样死去的,淹死在雷鸣般的掌声里[/COLOR]

使用道具 举报

天使
地狱 傲慢

帖子
14053
精华
1
积分
7454
金钱
2444
荣誉
20
人气
1
评议
0

27#
发表于 2010-10-11 19:16:40 |只看该作者
我表示我只管用 不管这几个函数是怎么实现的………………………………………………

使用道具 举报

帖子
4306
精华
0
积分
2155
金钱
2112
荣誉
0
人气
1
评议
0

28#
发表于 2010-10-11 19:56:55 |只看该作者
那篇Purdue大学的论文很有意思,学习算法和加密的时候曾经拜读过,这个数字0x5f3759df也很神奇,效率和精度都很完美。

Hell Freezes Over...

使用道具 举报

帖子
1907
精华
0
积分
974
金钱
3403
荣誉
0
人气
180
评议
0
29#
发表于 2010-10-11 20:04:29 |只看该作者
好帖子 看回帖就能看出来人受的教育程度  数值方法是工科学生研究生必修的    基础好点的本科也能会  学计算机的更不用说了

[ 本帖最后由 icame 于 2010-10-11 20:06 编辑 ]

使用道具 举报

帖子
31
精华
0
积分
16
金钱
208
荣誉
0
人气
0
评议
0
30#
发表于 2010-10-11 23:01:44 |只看该作者
-----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

使用道具 举报

帖子
31
精华
0
积分
16
金钱
208
荣誉
0
人气
0
评议
0
31#
发表于 2010-10-11 23:03:26 |只看该作者
-----Original Message-----
From: Terje Mathisen
Sent: 22 August 2005 07:49
Subject: Re: FW: Origin of fast approximated inverse square root

ryszard wrote:

> Hey Terje,
>
> This question has come up again since id released the source to Quake
> 3 Arena.
> > Are you the guy who wrote that fast implementation of inverse square root?
> If so, do you have a history of where it came from and how you came up
> with it? A whole bunch of hackers and geeks would love to know and
> since John says it wasn't him or likely Michael, was it you?

Hello Ryszard, and hello again John, it's been a few years since we last met. :-(

Thanks for giving me as a possible author, when I first saw the subject I did
indeed think it was some of my code that had been used. :-)

I wrote a very fast (pipelineable) & accurate invsqrt() 5+ years ago, to help
a Swede with a computational fluid chemistry problem.

His simulation runs used to take about a week on either Alpha or x86 systems,
with my modifications they ran in half the time, while delivering the exact
same final printed results (8-10 significant digits).

The code shown below is not the same as what I wrote, I would guess it mostly
stays within a fraction of a percent? The swede needed at least 48 sigificant
bits in his results, so I employed a much more straightforward table lookup
plus NR-iteration. Since water molecules contain three atoms it was quite
straightforward to calculate three such invsqrt() values in parallel, this was
enough to avoid almost all bubbles in the fp pipelines.

I do think I recognize the style of the Q3A code however, it looks a lot like
something you'll find in the old HAKMEM documents from MIT. :-)

Regards,

Terje

使用道具 举报

帖子
205
精华
0
积分
104
金钱
175
荣誉
0
人气
0
评议
0
32#
发表于 2010-10-11 23:06:28 |只看该作者
很强大,膜拜下先                                

使用道具 举报

帖子
31
精华
0
积分
16
金钱
208
荣誉
0
人气
0
评议
0
33#
发表于 2010-10-11 23:06:53 |只看该作者
-----Original Message-----
From: Gary Tarolli
Sent: Mon 05/09/2005 14:23
Subject: RE: FW: Origin of fast approximated inverse square root

A blast from the past!
I definitely recognize the code below, but I can't take credit for it.
I remember running across it over 10 years ago, and I also remember
rederiving it. I think it's just Newton-Raphson iteration with a very
clever first approx.

I also remember simulating different values for the hex constant
0x5f3759df. I may have done this for the IRIS indigo work I did,
or some consulting at Kubota, I'm not 100% sure.

Given the amount of math it does, and its accuracy, and not requiring
a table, it is a pretty great piece of code.

I especially like the integer ops
   i = 0x5f3759df - (i >> 1);
which actually is doing a floating point computation in integer - it
took a long time to figure out how and why this works, and I can't
remember the details anymore.

Ah those were the days - fast integer and slow floating point....

So it did pass by my keyboard many many years ago, I may have tweaked
the hex constant a bit or so, but other than that I can't take credit
for it, except that I used it a lot and probably contributed to its
popularity and longevity.

p.s. sorry in taking so long to reply

结论,这个算法是Gary Tarolli和他在SGI的同事于2001年左右发明的。

使用道具 举报

帖子
2911
精华
1
积分
1676
金钱
8922
荣誉
1
人气
34
评议
0
34#
发表于 2010-10-12 03:30:39 |只看该作者
天啊!值得膜拜,看了个大概懂,重新读一下看看。。牛牛迭代法算是见识过了。。卡马克的这个值绝对是神来之笔!!
EVE   Star Citizen   Elite Dangerous
LOL   Guild War 2   GTAV

CPU: Intel I7 4790K
RAM: HyperX FURY Series (2 x 8 GB) DDR3 1866 MHz CL10
MB: Gigabyte Z97N Gaming 5 Mini-ITX
GPU: Zotac GTX 980
SSD: Samsung 250 GB 850 EVO
SSHD: Seagate STBD1000400
Case: SilverStone SST-RVZ01 Raven Mini ITX Case

使用道具 举报

帖子
1427
精华
0
积分
737
金钱
1445
荣誉
2
人气
0
评议
0
35#
发表于 2010-10-12 05:01:41 |只看该作者
卡神就缺一个罗梅洛做设计。要是DOOM3当年有神人设计一下关卡,就不会被半条命2比下去了。

使用道具 举报

帖子
494
精华
0
积分
247
金钱
1843
荣誉
0
人气
0
评议
0
36#
发表于 2010-10-12 06:14:25 |只看该作者
当年高一数学期中考试全班平均分37
Q9550 oc3.4/Corsair H50/Evga 790i Ftw/Evga Gtx285 x2 Sli/Evga 98Gtx+ Physx only/Corsair Dominator Ddr3 1600 2gx2/Seagate 1T Raid 0/Evga Killer Xeno pro/Corsair Hx1000w/Hdd 6T/Thermaltake Spedo Advance/Win7-64

E8400 oc3.6/Scythe Ninja +Rev.b/Asus Striker II Formula/Msi 4890 Oc/Kingston Hyperx 1066 1gx2/Seagate 1T Raid0/Coolermaster Realpower 750w/Coolermaster Cm690/Win7-32

使用道具 举报

帖子
2911
精华
1
积分
1676
金钱
8922
荣誉
1
人气
34
评议
0
37#
发表于 2010-10-12 07:14:20 |只看该作者
悲剧的是,我拿VC6.0试验了一下,为毛计算精度有点低啊。。。。
EVE   Star Citizen   Elite Dangerous
LOL   Guild War 2   GTAV

CPU: Intel I7 4790K
RAM: HyperX FURY Series (2 x 8 GB) DDR3 1866 MHz CL10
MB: Gigabyte Z97N Gaming 5 Mini-ITX
GPU: Zotac GTX 980
SSD: Samsung 250 GB 850 EVO
SSHD: Seagate STBD1000400
Case: SilverStone SST-RVZ01 Raven Mini ITX Case

使用道具 举报

帖子
5460
精华
0
积分
2733
金钱
9518
荣誉
0
人气
29
评议
0
38#
发表于 2010-10-12 07:35:58 |只看该作者
原帖由 FLZ012 于 2010-10-11 19:16 发表
我表示我只管用 不管这几个函数是怎么实现的………………………………………………


用的结果就是看起来差不多的画面效果,卡神的只需要9600GT就流畅了,某游戏最少需要GT460才稳定60FPS
把以前买的几十本国产正版游戏全半价出了,顿时感觉心旷神怡。

使用道具 举报

帖子
9774
精华
0
积分
4906
金钱
5356
荣誉
0
人气
34
评议
0

39#
发表于 2010-10-12 09:29:50 |只看该作者
原帖由 icame 于 2010-10-11 20:04 发表
好帖子 看回帖就能看出来人受的教育程度  数值方法是工科学生研究生必修的    基础好点的本科也能会  学计算机的更不用说了

本科和学计算机的也不见得会,原因是多方面的,比如有的上学的时候就是混的、有的毕业以后不从事本专业及其相关行业的。。。。。。。。。。。。基本上就都忘的差不多了

使用道具 举报

帖子
652
精华
0
积分
326
金钱
690
荣誉
0
人气
0
评议
0
40#
发表于 2010-10-12 09:31:44 |只看该作者
原帖由 chenyiheng 于 2010-10-12 07:14 发表
悲剧的是,我拿VC6.0试验了一下,为毛计算精度有点低啊。。。。


反正是求一个向量正交化,0.1%的精度足够用。
你以为精确到小数点后一长串有意义么

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

手机版|Archiver|游侠NETSHOW论坛 ( 苏ICP备2023007791号 )

GMT+8, 2026-4-5 08:35 , Processed in 0.305829 second(s), 10 queries , Gzip On, Memcache On.

Powered by Discuz! X2

© 2001-2011 Comsenz Inc.

分享到