Lua笔记--number的存储
来源:互联网 发布:专业英语翻译软件 编辑:程序博客网 时间:2024/06/06 05:12
Lua 笔记–number的存储
Lua语言里面的数字类型是number,没有像C/C++里面那样多种多样,如果是这样的话,那么在计算机内数字就应该是按照浮点数存储的,而浮点数存储不是有不确定性吗?不会出现类似1+2=2.9999999999的错误吗?
这个问题在Roberto Ierusalimschy的《Programming In Lua》一书中进行了说明
Some people fear that even a simple increment or comparison can go weird with floating-point numbers. Reality, however, is not like that. Virtually all plat-forms nowadays follow the IEEE 754 standard for floating-point representation.Following this standard, the only possible source of errors is a representation error, which happens when a number cannot be exactly represented. An operation rounds its result only if that result has no exact representation. Any operation with a result that has an exact representation must give that exact result.
The fact is that any integer up to
253 (approximately1016 ) has an exact representation as a double-precision floating-point number. When you use a double to represent an integer, there is no rounding error at all, unless the number has an absolute value greater than253 . In particular, a Lua number can represent any 32-bit integer without rounding problems.
小于
简单地说,双精度浮点数能存储的有效位数最大是53,这里的位数是指化成二进制之后的位数,如果位数大于53,则存在不精确存储。而53位最多可以存储的整数即为
对IEEE754标准的理解
- Lua笔记--number的存储
- lua的学习笔记
- lua学习:lua程序设计的一些笔记
- 【Lua学习笔记】Lua中协程的使用
- 数据/配置 的存储方式 Lua篇
- Lua的string学习笔记
- 【Cocos2d-x Lua笔记六】游戏存储GameState
- [lua]Lua笔记
- lua学习笔记之Lua的function、closure和upvalue
- 笔记: Lua基础: Table, Array, Namespace, Lua的面向对象
- lua学习笔记1---VC下lua环境的搭建
- lua 学习笔记1(lua相关内容的编译)
- lua学习笔记之Lua的function、closure和upvalue
- Lua学习笔记6:C++和Lua的相互调用
- Lua笔记-关于lua table的C API
- Lua笔记-关于lua table的C API
- cocos-lua学习笔记(五)cocos2d-Lua类的实现
- Lua笔记-关于lua table的C API
- [bzoj4034][HAOI2015]树上操作
- 平面射影几何——齐次坐标
- OkHttp下载文件并带进度条
- 说说java NIO的一些个人总结
- webpack中的babel-loader
- Lua笔记--number的存储
- Linux 0.11
- 极限编程的最佳实践
- Java NIO使用及原理分析 (四)
- 官方安装文档解读SAP S4 HANA架构
- angularjs指令:transclude
- AJAX——响应
- 个人学习总结的部分java小知识与面试题(二)
- 基于深度学习的场景分类算法