log2() only works with double types?
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
atharva aalok
am 24 Okt. 2021
Kommentiert: atharva aalok
am 24 Okt. 2021
log2() seems to only work with 'double' types. It throws error when argument is int64.
num = 10000;
d = floor(num / 7);
a = log2(d);
disp(a);
d = int64(num / 7);
b = log2(double(d));
disp(b);
b = log2(d);
disp(b);
0 Kommentare
Akzeptierte Antwort
Simon Chan
am 24 Okt. 2021
Check MATLAB documentation and this fucntion log2 supports type single or double as the input argument type.
3 Kommentare
Steven Lord
am 24 Okt. 2021
The output of the log2 function is the same type as the input. [This is a general pattern for many element-wise functions.] There are only a handful of int64 numbers whose base 2 log is representable as an int64 number. If it were defined for int64 we'd likely have a lot of people complaining about "bugs" in log2 when it was returning the correct answer just not the answer they expected.
log2Int64 = @(x) int64(log2(double(x)));
x = int64(10:20);
y = log2Int64(x)
check = x - 2.^y % Is this what you would expect?
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Chebyshev finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!