Matlab中具有双精度的算术精度

Matlab中具有双精度的算术精度

本文介绍了Matlab中具有双精度的算术精度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一点麻烦,了解这些双精度如何影响Matlab中算术运算的结果。我以为,既然a& b是双倍的,他们将能够进行这样的精确度的操作。我意识到可能会出现四舍五入的错误,但是由于这些数字在64位数字表示之内,我认为这不是一个问题。

  a = 1.22e-45 
b = 1
a == 0
ans = 0%a不等于零
(a + b)= = 1
ans = 1

如何能够承载足够的精度来识别!= 0,但是当被添加到1时,它不会显示任何变化。

解决方案

浮动精确度相对于数字本身的比例。



在给出的具体示例中,1.22e-45可以单独表示,因为指数可以调整为代表10 ^ -45或大约2 ^ -150。



另一方面,1.0以二进制表示,标度为2 ^ 0(即1) p>

要添加这两个值,您需要对齐其小数点(呃...二进制点),这意味着所有精度为1.22e-45当然,IEEE双精度浮点值只有53位尾数(精度),这意味着在1.0,1.22e-45实际上是零。


I am having a bit of trouble understanding how the precision of these doubles affects the outcome of arithmetic operations in Matlab. I thought that since both a & b are doubles they would be able to carry out operations up to that precision. I realize there can be round-off error but since these numbers are well within the 64-bit number representation I didn't think that would be an issue.

a = 1.22e-45
b = 1
a == 0
   ans = 0  %a is not equal to zero
(a + b) == 1
   ans = 1

How come it is able to carry enough precision to recognize a != 0 but when added to 1 it doesn't show any change.

解决方案

"Floating" point means just that--the precision is relative to the scale of the number itself.

In the specific example you gave, 1.22e-45 can be represented alone because the exponent can be adjusted to represent 10^-45, or approximately 2^-150.

On the other hand, 1.0 is represented in binary with scale 2^0 (i.e., 1).

To add these two values, you need to align their decimal points (er...binary points), meaning that all of the precision of 1.22e-45 is shifted 150-odd bits to the right.

Of course, IEEE double precision floating point values only have 53 bits of mantissa (precision), meaning that at the scale of 1.0, 1.22e-45 is effectively zero.

这篇关于Matlab中具有双精度的算术精度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 10:08