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'
댓글 수: 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!