Mercurial > octave
changeset 31199:8bd9b64aeb01
maint: Merge stable to default.
author | Markus Mützel <markus.muetzel@gmx.de> |
---|---|
date | Wed, 24 Aug 2022 17:19:26 +0200 |
parents | 8d4c87e88d0e (current diff) 863730dd0f83 (diff) |
children | a8b0acc018a2 |
files | |
diffstat | 1 files changed, 4 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/general/nextpow2.m Tue Aug 23 19:45:19 2022 +0200 +++ b/scripts/general/nextpow2.m Wed Aug 24 17:19:26 2022 +0200 @@ -49,10 +49,8 @@ error ("nextpow2: X must be numeric"); endif - [f, n] = log2 (abs (x)); - idx = (n == 0); # Find any failures of log2 function (n == 0) - n(idx) = f(idx); # and copy over value. - n(f == 0.5)--; + n = ceil (log2 (abs (x))); + n(x == 0) = 0; # special case endfunction @@ -64,6 +62,8 @@ %!assert (nextpow2 (-17), 5) %!assert (nextpow2 (-31), 5) %!assert (nextpow2 (1:17), [0 1 2 2 3 3 3 3 4 4 4 4 4 4 4 4 5]) +%!assert (nextpow2 (0.5), -1) +%!assert (nextpow2 (0.6), 0) ## Special cases %!assert (nextpow2 (0), 0) %!assert (nextpow2 (1), 0)