MATLAB data type expression problem
6 ビュー (過去 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 ?
0 件のコメント
採用された回答
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 件のコメント
その他の回答 (0 件)
参考
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!