提高double /float 强转为int类型的速度
来源:互联网 发布:淘宝修改中差评 编辑:程序博客网 时间:2024/05/01 13:54
/* double到整数的转换超强的算法,无误差 (利用了IEEE浮点编码格式) ,比使用C语言 int a = (int)(浮点数)快很多*/
static inline int DoubleToInt_IEEE(double value)
{
static const double magic = 6755399441055744.0; // (1<<51) | (1<<52)
double tmp = value + magic;
return *(int*)&tmp;
}
/* float到整数, 允许存在误差情况使用*/
static inline int Fast_FloatToInt_IEEE(float value)
{
static const float magic_f = (3<<21);
static const long magic_i = 0x4ac00000;
float ftmp = value + magic_f;
return (*((int*)&ftmp)-magic_i) >> 1;
}
static_cast<int>(f)
最快
- 提高double /float 强转为int类型的速度
- 字符串转为float,int,double类型
- Int,long,float,double类型
- int类型定义,float、double类型引用造成的结果
- String与int float double 类型之间的转换
- int long longlong float double类型数据的范围
- 关于int,float,double与Integer、Float、Double的理解
- double float 类型的输出
- js中将int类型转为float类型,并取位
- C++中将string类型转换为int, float, double类型
- C++中将string类型转换为int, float, double类型
- C++中将string类型转换为int, float, double类型
- C++中将string类型转换为int, float, double类型
- string类型转换为int, float, double类型、随机数生成
- 如何得到int float double、...的范围。
- int, float和double的内存结构
- int,long,float,double 的最小值,最大值
- int float double 忽略的细节
- 彻底认清PHP单例模式
- 解决:SQL1005N 在本地数据库目录或系统数据库目录中已经存在数据库别名
- 网络不通,误删路由信息 (hp unix机器)
- POJ 3093 Margaritas on the River Walk
- MyEclipse卡死的解决方案
- 提高double /float 强转为int类型的速度
- Myeclipse优化
- 彪悍的C#概念图解
- Workspace in use or cannot be created, choose a different one.
- 0715日报
- 初次使用配置
- DP基础问题若干(ACM/ICPC)
- 遍历某个目录,生成目录树
- 虚拟屏幕:云-移动融合的第三要素