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 |
3321
|
17 ## -*- texinfo -*- |
|
18 ## @deftypefn {Function File} {} nextpow2 (@var{x}) |
|
19 ## If @var{x} is a scalar, returns the first integer @var{n} such that |
|
20 ## @iftex |
|
21 ## @tex |
|
22 ## $2^n \ge |x|$. |
|
23 ## @end tex |
|
24 ## @end iftex |
|
25 ## @ifinfo |
|
26 ## 2^n >= abs (x). |
|
27 ## @end ifinfo |
|
28 ## |
|
29 ## If @var{x} is a vector, return @code{nextpow2 (length (@var{x}))}. |
|
30 ## @end deftypefn |
|
31 |
|
32 ## See also: pow2 |
2539
|
33 |
|
34 ## Author: KH <Kurt.Hornik@ci.tuwien.ac.at> |
|
35 ## Created: 7 October 1994 |
|
36 ## Adapted-By: jwe |
|
37 |
|
38 function n = nextpow2 (x) |
|
39 |
|
40 if (nargin != 1) |
|
41 usage ("nextpow2 (x)"); |
|
42 endif |
|
43 |
2816
|
44 if (! (is_scalar (x) || is_vector (x))) |
2539
|
45 error ("nextpow2: x must be a scalar or a vector"); |
|
46 endif |
2816
|
47 |
|
48 t = length (x); |
|
49 if (t > 1) |
|
50 x = t; |
|
51 endif |
2539
|
52 |
|
53 [f, n] = log2 (abs (x)); |
|
54 if (f == 0.5) |
|
55 n = n - 1; |
|
56 endif |
|
57 |
|
58 endfunction |