Scalar Multiplication
10 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
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
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
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 Center 和 File Exchange 中查找有关 Number Theory 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!