当前位置:网站首页>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中的附件里,可点击下载。进一步了解,可联系们。
边栏推荐
- 高考的意义是什么
- [Fantasy 4] the transformation from U3D to UE4
- Read H264 parameters from mediarecord recording
- In the face of uncertainty, the role of supply chain
- JSP webshell免杀——JSP的基础
- [Lua] summary of common knowledge points (including common interview sites)
- Flink submitter
- Shapiro Wilk normal analysis by SPSS
- 【TS】1368- 秒懂 TypeScript 泛型工具类型!
- Record attributeerror: 'nonetype' object has no attribute 'nextcall‘
猜你喜欢
[pit avoidance guide] pit encountered using ugui: the text component cannot indent the first line by two spaces
Session cookies and tokens
HDU1236 排名(结构体排序)
Flutter——Canvas自定义曲线图
Is this code PHP MySQL redundant?
(5) Gear control setting of APA scene construction
4. Random variables
4.随机变量
stm32和電機開發(上比特系統)
Kustomize使用手册
随机推荐
Retrofit's callback hell is really vulnerable in kotlin synergy mode!
PCL 投影点云
AttributeError: type object ‘Image‘ has no attribute ‘fromarray‘
Leetcode+ 76 - 80 storm search topic
MYSQL关键字
Redis set password
JSP webshell免杀——JSP的基础
07 data import sqoop
MySQL environment configuration
PCL Eigen介绍及简单使用
Considerations for Apache deploying static web page projects
01-spooldir
Flutter——Canvas自定义曲线图
UWA报告使用小技巧,你get了吗?(第四弹)
SPSS做Shapiro-Wilk正态分析
[unity3d] cannot correctly obtain the attribute value of recttransform, resulting in calculation error
02-taildir source
Allure -- common configuration items
集成学习概览
【TS】1368- 秒懂 TypeScript 泛型工具类型!