当前位置:网站首页>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中的附件里,可点击下载。进一步了解,可联系们。
边栏推荐
- Postman -- use
- The nanny level tutorial of flutter environment configuration makes the doctor green to the end
- UWA报告使用小技巧,你get了吗?(第四弹)
- 互联网快讯:腾讯会议应用市场正式上线;Soul赴港递交上市申请书
- Shell programming 01_ Shell foundation
- Importing tables from sqoop
- VSCode工具使用
- JSP webshell免杀——JSP的基础
- 大华设备播放过程中设置播放速度
- Is this code PHP MySQL redundant?
猜你喜欢

Open the encrypted SQLite method with sqlcipher

07 data import sqoop
![[visual studio] every time you open a script of unity3d, a new vs2017 will be automatically reopened](/img/c3/aec0a9fb79cf94b3575d95530aa8e8.png)
[visual studio] every time you open a script of unity3d, a new vs2017 will be automatically reopened

VLAN experiment

Postman -- use

使用sqlcipher打开加密的sqlite方法

MPLS experiment

【TS】1368- 秒懂 TypeScript 泛型工具类型!

13.信号量临界区保护

Webui automated learning
随机推荐
Win11 arm系统配置.net core环境变量
UWA报告使用小技巧,你get了吗?(第四弹)
SUS系统可用性量表
MySQL lethal serial question 3 -- are you familiar with MySQL locks?
(五)APA场景搭建之挡位控制设置
JSP webshell免杀——JSP的基础
618再次霸榜的秘密何在?耐克最新财报给出答案
Windows环境MySQL8忘记密码文件解决方案
Dialogue Wu Gang: why do I believe in the rise of "big country brands"?
UVM——Callback
PCL之K-d树与八叉树
Flutter——Canvas自定义曲线图
Pytest framework implements pre post
Shutter - canvas custom graph
AttributeError: type object ‘Image‘ has no attribute ‘fromarray‘
618 what is the secret of dominating the list again? Nike's latest financial report gives the answer
sqoop创建job出现的一系列问题解决方法
Analysis of hot spots in AI technology industry
Postman -- use
[Fantasy 4] introduction and use of UMG components (under update...)