Mercurial > hg > octave-nkf
annotate scripts/general/nextpow2.m @ 8920:eb63fbe60fab
update copyright notices
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sat, 07 Mar 2009 10:41:27 -0500 |
parents | 81d6ab3ac93c |
children | c1fff751b5a8 |
rev | line source |
---|---|
7017 | 1 ## Copyright (C) 1995, 1996, 1997, 1999, 2000, 2002, 2004, 2005, 2006, |
8920 | 2 ## 2007, 2009 Kurt Hornik |
3426 | 3 ## |
3922 | 4 ## This file is part of Octave. |
5 ## | |
6 ## Octave is free software; you can redistribute it and/or modify it | |
7 ## under the terms of the GNU General Public License as published by | |
7016 | 8 ## the Free Software Foundation; either version 3 of the License, or (at |
9 ## your option) any later version. | |
3426 | 10 ## |
3922 | 11 ## Octave is distributed in the hope that it will be useful, but |
2539 | 12 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
3426 | 14 ## General Public License for more details. |
15 ## | |
2539 | 16 ## You should have received a copy of the GNU General Public License |
7016 | 17 ## along with Octave; see the file COPYING. If not, see |
18 ## <http://www.gnu.org/licenses/>. | |
2539 | 19 |
3321 | 20 ## -*- texinfo -*- |
21 ## @deftypefn {Function File} {} nextpow2 (@var{x}) | |
22 ## If @var{x} is a scalar, returns the first integer @var{n} such that | |
23 ## @iftex | |
24 ## @tex | |
25 ## $2^n \ge |x|$. | |
26 ## @end tex | |
27 ## @end iftex | |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7017
diff
changeset
|
28 ## @ifnottex |
3321 | 29 ## 2^n >= abs (x). |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7017
diff
changeset
|
30 ## @end ifnottex |
3426 | 31 ## |
3321 | 32 ## If @var{x} is a vector, return @code{nextpow2 (length (@var{x}))}. |
5642 | 33 ## @seealso{pow2} |
3321 | 34 ## @end deftypefn |
2539 | 35 |
5428 | 36 ## Author: KH <Kurt.Hornik@wu-wien.ac.at> |
2539 | 37 ## Created: 7 October 1994 |
38 ## Adapted-By: jwe | |
39 | |
40 function n = nextpow2 (x) | |
3426 | 41 |
2539 | 42 if (nargin != 1) |
6046 | 43 print_usage (); |
2539 | 44 endif |
45 | |
4030 | 46 if (! (isscalar (x) || isvector (x))) |
2539 | 47 error ("nextpow2: x must be a scalar or a vector"); |
48 endif | |
2816 | 49 |
50 t = length (x); | |
51 if (t > 1) | |
52 x = t; | |
53 endif | |
3426 | 54 |
2539 | 55 [f, n] = log2 (abs (x)); |
56 if (f == 0.5) | |
57 n = n - 1; | |
58 endif | |
3426 | 59 |
2539 | 60 endfunction |