question on addition of numbers.
1 view (last 30 days)
Show older comments
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 Comments
Accepted Answer
FirefoxMetzger
on 15 Aug 2016
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
More Answers (1)
Azzi Abdelmalek
on 15 Aug 2016
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 Comments
John D'Errico
on 15 Aug 2016
You CANNOT recover a from c, when using double precision. NEVER. A double lacks sufficient precision to do so.
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!