MATLAB data type expression problem

7 Ansichten (letzte 30 Tage)
xingxingcui
xingxingcui am 30 Sep. 2017
Beantwortet: OCDER am 30 Sep. 2017
(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 ?

Akzeptierte Antwort

OCDER
OCDER am 30 Sep. 2017
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

Weitere Antworten (0)

Kategorien

Mehr zu Logical finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!