15年2个月前IP:未同步
337332
3楼
计算机算平方根用牛顿迭代。。。或者。。。下面这个fuck的方法

float InvSqrt(float x)
{
    float xhalf = 0.5f*x;
    int i = *(int*)&x; // get bits for floating VALUE
    i = 0x5f375a86- (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;
}


参考:一个sqrt函数引发的血案
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
attachment icon InvSqrt.pdf 147.71KB PDF 373次下载 预览
+200
科创币
ehco
2011/11/18
重大释疑!数学很奥妙啊,这人肯定不是地球人!
评论
文号 / 337332

千古风流
名片发私信
学术分 3
总主题 111 帖总回复 1523 楼拥有证书:学者 笔友
注册于 2010/07/01 21:45:51最后登录 2017/02/15 16:37:06
主体类型:个人
所属领域:无
认证方式:邮箱
IP归属地:0

个人简介

暂未填写
笔记
{{note.content}}
{{n.user.username}}
{{fromNow(n.toc)}} {{n.status === noteStatus.disabled ? "已屏蔽" : ""}} {{n.status === noteStatus.unknown ? "正在审核" : ""}} {{n.status === noteStatus.deleted ? '已删除' : ''}}
  • 编辑
  • 删除
  • {{n.status === 'disabled' ? "解除屏蔽" : "屏蔽" }}
我也是有底线的