当前位置:网站首页>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中的附件里,可点击下载。进一步了解,可联系们。
边栏推荐
- 02-taildir source
- UWA report uses tips. Did you get it? (the fourth bullet)
- "Matching" is true love, a new attitude for young people to make friends
- SQOOP 1.4.6 INSTALL
- 4. Random variables
- Transport Optimization abstraction
- 拆解美图SaaS:开着飞机换引擎
- Lunix reallocates root and home space memory
- UVM learning - build a simple UVM verification platform
- 集成学习概览
猜你喜欢
对话吴纲:我为什么笃信“大国品牌”的崛起?
How to get the password of cpolar?
4.随机变量
2. Hacking lab script off [detailed writeup]
JSP webshell免杀——webshell免杀
MySQL environment configuration
[Fantasy 4] introduction and use of UMG components (under update...)
Redis set password
使用sqlcipher打开加密的sqlite方法
Beautiful and intelligent, Haval H6 supreme+ makes Yuanxiao travel safer
随机推荐
Solutions to a series of problems in sqoop job creation
Redis set password
MPLS experiment
The nanny level tutorial of flutter environment configuration makes the doctor green to the end
Pywin32 opens the specified window
JSP webshell免杀——webshell免杀
Session cookies and tokens
flume 190 INSTALL
2021-09-12
UVM learning - object attribute of UVM phase
13.信号量临界区保护
(五)APA场景搭建之挡位控制设置
Pytest-- test report allure configuration
Win11 arm系统配置.net core环境变量
大华设备播放过程中设置播放速度
高考的意义是什么
12. Process synchronization and semaphore
Postman -- use
面对不确定性,供应链的作用
PCL之K-d树与八叉树