• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
seventh成长中---
博客园    首页    新随笔    联系   管理    订阅  订阅
快速开根模板(卡马克算法)

精度不是很高  代码如下

 1 float SqrtByCarmack( float number )
 2 {
 3     int i;
 4     float x2, y;
 5     const float threehalfs = 1.5F;
 6 
 7     x2 = number * 0.5F;
 8     y  = number;
 9     i  = * ( int * ) &y;
10     i  = 0x5f375a86 - ( i >> 1 );
11     y  = * ( float * ) &i;
12     y  = y * ( threehalfs - ( x2 * y * y ) );
13     y  = y * ( threehalfs - ( x2 * y * y ) );
14     y  = y * ( threehalfs - ( x2 * y * y ) );
15     return number*y;
16 }

 

posted on 2017-08-11 10:17  xseventh  阅读(369)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3