MATLAB data type expression problem

7 次查看(过去 30 天)
(2^61-5):(2^61),This number can't get a vector with 5 elements,why?
Another question,In matlab command window ,input :
a = isequal(int64(2^63-2^9) , int64(2^63-2^1))
the result is:
a =
logical
1
why a == 1 ,not zero ?

采纳的回答

OCDER
OCDER 2017-9-30
The issue is caused because MATLAB uses 16-digits of precision for double calculations, and 2^61 exceeds 16 digits. The excess digits are just rounded off, hence (2^63 - 2) does not see the " - 2" adjustment after rounding.
To fix the issue, immediately convert to int64 for larger numbers > 16 digits of precision.
(2^61-5):(2^61) %Gives you 1 number, exceeds 16-digit precision
int64(2^61)-5:int64(2^61) %Gives you 6 numbers, within range
a = isequal(int64(2^63 - 2^9) , int64(2^63 - 2)) %Returns 1, since 2^63 exceeds 16-digit precision (19-digit needed)
a = isequal(int64(2^63)- 2^9 , int64(2^63)-2) %Returns 0

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!