cloud

  C++博客 :: 首页 :: 联系 :: 聚合  :: 管理
  29 Posts :: 1 Stories :: 4 Comments :: 0 Trackbacks

常用链接

留言簿(5)

我参与的团队

搜索

  •  

最新评论

阅读排行榜

评论排行榜

 

/* 来至 Quake 3 的源码 */
float CarmSqrt(float x){
    union
    
{
        
int intPart;
        
float floatPart;
    }
 convertor;
    union
    
{
        
int intPart;
        
float floatPart;
    }
 convertor2;
    convertor.floatPart 
= x;
    convertor2.floatPart 
= x;
    convertor.intPart 
= 0x1FBCF800 + (convertor.intPart >> 1);
    convertor2.intPart 
= 0x5f3759df - (convertor2.intPart >> 1);
    
return 0.5f*(convertor.floatPart + (x * convertor2.floatPart));
}
posted on 2007-05-11 12:00 cloud 阅读(2769) 评论(4)  编辑 收藏 引用 所属分类: 游戏

Feedback

# re: 一个快速开方的函数 2007-05-12 12:43 天衣有缝
fpu里面好像就提供了类似sqrt指令,一般的编译器选项默认都是使用软浮点  回复  更多评论
  

# re: 一个快速开方的函数 2007-05-13 17:13 pengkuny
请问怎么解释?位运算头痛  回复  更多评论
  

# re: 一个快速开方的函数 2008-01-10 04:19 Fox
不仅仅是位运算的问题,还涉及到float与int的存储对位问题 :|  回复  更多评论
  

# re: 一个快速开方的函数 2009-05-04 19:17 aduhupu
我测试了一下这个函数和C库中的sqrt函数对比,发现效率上并没有什么提升,甚至有时还不如sqrt的效率,我测试平台是VS2008  回复  更多评论
  


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理