question on addition of numbers.
2 ビュー (過去 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'
0 件のコメント
採用された回答
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
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 件のコメント
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 Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!