Scalar Multiplication

조회 수: 5 (최근 30일)
somesh bandari
somesh bandari 2012년 5월 26일
Hi there, I tried to multiply 1000000000 (9 zeros) and 100000000000000 (14 zeros). The answer ideally should be 1 followed by 23 zeros, but MATLAB is showing 99999999999999992000000.00.
I tried to check by subtracting 1*e23 - 99999999999999992000000.00, the answer was surprisingly zero. This means that 99999999999999992000000.00 is equal to 1*e23.
Can you please explain the reason. Also, I want my answer to display 1 followed by 23 zeros exactly as it has to be. Could you please help me to achieve this.
Regards, Somesh

채택된 답변

Walter Roberson
Walter Roberson 2012년 5월 26일
You need to use the Symbolic Toolbox, or the MATLAB File Exchange contribution "vpi" (John D'Errico)
The immediate problem you are encountering is that 10^23 requires 77 bits to represent, but IEEE 754 double precision floating point numbers have only 53 bits of precision. Switching to uint64() will not work for you because uint64() would have only 64 bits and you need 77 bits.
The largest power of 10 that MATLAB can store exactly in an IEEE 754 double precision number is 10^15.
The largest power of 10 that can be stored exactly in a uint64() unsigned 64 bit integer is 10^18
  댓글 수: 6
James Tursa
James Tursa 2012년 5월 26일
E.g.,
>> num2strexact(10^16)
ans =
1e16
>> num2strexact(10^17)
ans =
1e17
>> num2strexact(10^18)
ans =
1e18
>> num2strexact(10^19)
ans =
1e19
>> num2strexact(10^20)
ans =
1e20
>> num2strexact(10^21)
ans =
1e21
>> num2strexact(10^22)
ans =
1e22
>> num2strexact(10^23)
ans =
9.9999999999999991611392e22
James Tursa
James Tursa 2012년 5월 26일
Regarding the 2^53 limit, I would say that is a likely guess. I just haven't checked. Also, I would agree that this may not be consistent across different MATLAB versions, particularly when TMW implemented new uint64 arithmetic recently.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Number Theory에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by