2539
|
1 ## Copyright (C) 1995, 1996 Kurt Hornik |
|
2 ## |
|
3 ## This program is free software; you can redistribute it and/or modify |
|
4 ## it under the terms of the GNU General Public License as published by |
|
5 ## the Free Software Foundation; either version 2, or (at your option) |
|
6 ## any later version. |
|
7 ## |
|
8 ## This program is distributed in the hope that it will be useful, but |
|
9 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
11 ## General Public License for more details. |
|
12 ## |
|
13 ## You should have received a copy of the GNU General Public License |
|
14 ## along with this file. If not, write to the Free Software Foundation, |
|
15 ## 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
16 |
|
17 ## usage: nextpow2 (x) |
|
18 ## |
|
19 ## If x is a scalar, returns the first integer n such that |
|
20 ## 2^n >= abs (x). |
|
21 ## |
|
22 ## If x is a vector, return nextpow2 (length (x)). |
|
23 |
|
24 ## Author: KH <Kurt.Hornik@ci.tuwien.ac.at> |
|
25 ## Created: 7 October 1994 |
|
26 ## Adapted-By: jwe |
|
27 |
|
28 function n = nextpow2 (x) |
|
29 |
|
30 if (nargin != 1) |
|
31 usage ("nextpow2 (x)"); |
|
32 endif |
|
33 |
2816
|
34 if (! (is_scalar (x) || is_vector (x))) |
2539
|
35 error ("nextpow2: x must be a scalar or a vector"); |
|
36 endif |
2816
|
37 |
|
38 t = length (x); |
|
39 if (t > 1) |
|
40 x = t; |
|
41 endif |
2539
|
42 |
|
43 [f, n] = log2 (abs (x)); |
|
44 if (f == 0.5) |
|
45 n = n - 1; |
|
46 endif |
|
47 |
|
48 endfunction |