博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
快速atof()函数
阅读量:6904 次
发布时间:2019-06-27

本文共 861 字,大约阅读时间需要 2 分钟。

/*
shamelessly ripped from irrlicht3d engine.
*/
const
 
float
 fast_atof_table[] 
=
 {
    
0
.f,
    
0.1f
,
    
0.01f
,
    
0.001f
,
    
0.0001f
,
    
0.00001f
,
    
0.000001f
,
    
0.0000001f
,
    
0.00000001f
,
    
0.000000001f
,
    
0.0000000001f
,
    
0.00000000001f
,
    
0.000000000001f
,
    
0.0000000000001f
,
    
0.00000000000001f
,
    
0.000000000000001f
};
inline 
const
 
char
*
 fast_atof_move_const(
const
 
char
*
 c, 
float
&
 
out
)
{
    
bool
 inv 
=
 
false
;
    
char
 
*
t;
    
float
 f;
    
if
 (
*
c
==
-
'
)
    {
        c
++
;
        inv 
=
 
true
;
    }
    f 
=
 (
float
)strtol(c, 
&
t, 
10
);
    c 
=
 t;
    
if
 (
*
==
 ‘.’)
    {
        c
++
;
        
float
 pl 
=
 (
float
)strtol(c, 
&
t, 
10
);
        pl 
*=
 fast_atof_table[t
-
c];
        f 
+=
 pl;
        c 
=
 t;
        
if
 (
*
==
 ‘e’)
        {
            
++
c;
            
float
 exp 
=
 (
float
)strtol(c, 
&
t, 
10
);
            f 
*=
 (
float
)pow(
10.0f
, exp);
            c 
=
 t;
        }
    }
    
if
 (inv)
        f 
*=
 
-
1.0f
;
    
out
 
=
 f;
    
return
 c;
}
inline 
float
 fast_atof(
const
 
char
*
 c)
{
    
float
 ret;
    fast_atof_move_const(c, ret);
    
return
 ret;

转载地址:http://tqmdl.baihongyu.com/

你可能感兴趣的文章
flex 容器填充渐变的背景颜色
查看>>
vim 中wc 的用法
查看>>
AMQ资料
查看>>
android选择图片或拍照图片上传到服务器(包括上传参数)
查看>>
眼前再次迷茫
查看>>
day6 python学习随笔。
查看>>
foxit updater.exe does not exist的解决方法
查看>>
LENGTH 和 CHAR_LENGTH 的区别
查看>>
Actor初识
查看>>
Linux中pam认证详解(上)
查看>>
glusterfs安装记录
查看>>
【VMware虚拟化解决方案】VMware Horizon View Client 各平台配置文档
查看>>
java线程池
查看>>
Linux内核线程
查看>>
Linux目录及文件权限V1.0
查看>>
Linux cp时总询问是否覆盖,怎样让它不询问直接覆盖
查看>>
Java学习进度(2013.03.12)—Struts2学习一
查看>>
Docker&harbor
查看>>
电脑启动不起来
查看>>
六、CPU优化(2)超线程
查看>>