question on addition of numbers.

1 次查看(过去 30 天)
I have 2 numbers. a=11.699124064044344*2^192 and b=-17.935606820123120*2^252. adding a and b in MATLAB gives me the c=-1.2980e+77 (c=a+b). c-b gives me zero instead of 'a' value.
How to get back 'a' from 'c'

采纳的回答

FirefoxMetzger
FirefoxMetzger 2016-8-15
The simple answer is that a double is not precise enough to represent a + b .
A double is represented using IEEE® Standard 754 . Which (very roughly) stores variables as (sign) * 1.abcdef...*10^(XYZ) where all the numbers are binary.
Representing variable a as X * 10^252 means that X has a lot of leading zeros (0.000...00001169912...). At some point this takes more then the 52 bit to represent the number, so the standard tells us to round the 53nd bit, which is 0. All leading digits are also 0. Thus a = 0 * 10^252 (due to lack of precision). Logically a + b = b if we account for this lack of precision.
To still calculate correctly concider digits which are variable precision numbers. However be advised that they might be a lot slower when computing

更多回答(1 个)

Azzi Abdelmalek
Azzi Abdelmalek 2016-8-15
when I run
a=11.699124064044344*2^192
b=-17.935606820123120*2^254
c=a+b
isequal(c,b)
c and b are equal, that's why c-b is 0. To understand the reason, read this http://matlab.wikia.com/wiki/FAQ#Why_is_0.3_-_0.2_-_0.1_.28or_similar.29_not_equal_to_zero.3F
  2 个评论
Ashwini
Ashwini 2016-8-15
Iam finding difficult to understand the concept. The content in the link says "some floating point numbers can not be represented exactly in binary form". Does that mean i cannot recover 'a' from 'c' in the above example. Please let me know if there is any method to recover 'a'. Please share the code for it if possible.
Thanks ....
John D'Errico
John D'Errico 2016-8-15
You CANNOT recover a from c, when using double precision. NEVER. A double lacks sufficient precision to do so.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by