当前位置:网站首页>LabVIEW为什么浮点数会丢失精度
LabVIEW为什么浮点数会丢失精度
2022-07-02 07:13:00 【LabVIEW开发】
LabVIEW为什么浮点数会丢失精度
在编程环境中使用浮点数或双精度浮点数的时候发觉数字的值会有微小的变化。比如输入2.4的时候显示的是2.3999999999999999。为什么浮点数会出现这种不准确的情况呢?
解答: 造成浮点数不精确的主要原因有两个:
十进制数的二进制表示可能不够精确
浮点数或是双精度浮点数无法精确表示的情况并不少见。浮点数值没办法用十进制来精确表示的原因要归咎于CPU表示浮点数的方法。这样的话就可能会牺牲一些精度,有些浮点数运算也会引入误差。以上面提到的情况为例,2.4的二进制表示并非就是精确的2.4。反而最为接近的二进制表示是 2.3999999999999999。原因在于浮点数由两部分组成:指数和尾数。浮点数的值实际上是由一个特定的数学公式计算得到的。
如果想得到这个公式或是尾数的更多资料,可以参考“What is Mantissa?”文章。
所遇到的精度损失会在任何操作系统和编程环境中遇到。
注意:可以使用BinaryCoded Decimal (BCD)库来保持精度。BCD数字编码方法会把每一个十进制数字位单独编码。如果想要知道BCD的更多消息,可以参考文章“What is Binary Coded Decimal(BCD)?”
想要了解这种精度损失的更多信息可以参考IEEE/ANSI Standard 754-1985,这篇文章包括Standardfor Binary Floating Point Arithmetic。
类型失配
可能混合了浮点数和双精度浮点数类型。请确定在进行数学运算的时候所有的数据类型全部相同。
注意:float类型的变量只有7位的精度,而double类型的变量有15位的精度。

编辑
添加图片注释,不超过 140 字(可选)
LabVIEW、LabVIEW开发、LabVIEW编程、LabVIEW程序
上文中提到的例子和资料,均在word中的附件里,可点击下载。进一步了解,可联系们。
边栏推荐
- "Talking about podcasts" vol.352 the age of children: breaking the inner scroll, what can we do before high school?
- MySQL lethal serial question 3 -- are you familiar with MySQL locks?
- Kustomize user manual
- lunix重新分配root 和 home 空间内存
- 《实习报告》Skywalking分布式链路追踪?
- [unity3d] production progress bar - make image have the functions of filled and sliced at the same time
- [Lua] summary of common knowledge points (including common interview sites)
- [Fantasy 4] the transformation from U3D to UE4
- Ks009 implement pet management system based on SSH
- 2021-09-12
猜你喜欢
随机推荐
MYSQL关键字
HDU1236 排名(结构体排序)
The nanny level tutorial of flutter environment configuration makes the doctor green to the end
Convert yv12 to rgb565 image conversion, with YUV to RGB test
Win11 arm系统配置.net core环境变量
使用sqlcipher打开加密的sqlite方法
07 data import sqoop
PCL 点云转深度图像
2021-09-12
01安装虚拟机
《MySQL 8 DBA基础教程》简介
12. Process synchronization and semaphore
UVM——Callback
Lunix reallocates root and home space memory
快速做出原型
Solutions to a series of problems in sqoop job creation
MYSQL环境配置
13.信号量临界区保护
Analysis of hot spots in AI technology industry
MongoDB-快速上手MongoDB命令行的一些简单操作