Mercurial > hg > octave-nkf
annotate scripts/general/nextpow2.m @ 12541:dd2c70b30f28
Add tests for ifftshift.m
author | Robert T. Short <octave@phaselockedsystems.com.com> |
---|---|
date | Sat, 26 Mar 2011 06:50:12 -0700 |
parents | fd0a3ac60b0e |
children | 9e7ebbaf69ff |
rev | line source |
---|---|
11523 | 1 ## Copyright (C) 1995-2011 Kurt Hornik |
3426 | 2 ## |
3922 | 3 ## This file is part of Octave. |
4 ## | |
5 ## Octave is free software; you can redistribute it and/or modify it | |
6 ## under the terms of the GNU General Public License as published by | |
7016 | 7 ## the Free Software Foundation; either version 3 of the License, or (at |
8 ## your option) any later version. | |
3426 | 9 ## |
3922 | 10 ## Octave is distributed in the hope that it will be useful, but |
2539 | 11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
3426 | 13 ## General Public License for more details. |
14 ## | |
2539 | 15 ## You should have received a copy of the GNU General Public License |
7016 | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | |
2539 | 18 |
3321 | 19 ## -*- texinfo -*- |
20 ## @deftypefn {Function File} {} nextpow2 (@var{x}) | |
9141
c1fff751b5a8
Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
21 ## If @var{x} is a scalar, return the first integer @var{n} such that |
3321 | 22 ## @tex |
9167
1231b1762a9a
Simplify TeXinfo and eliminate use of @iftex in arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9141
diff
changeset
|
23 ## $2^n \ge |x|$. |
3321 | 24 ## @end tex |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7017
diff
changeset
|
25 ## @ifnottex |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
9167
diff
changeset
|
26 ## 2^n @geq{} abs (x). |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7017
diff
changeset
|
27 ## @end ifnottex |
3426 | 28 ## |
3321 | 29 ## If @var{x} is a vector, return @code{nextpow2 (length (@var{x}))}. |
9141
c1fff751b5a8
Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
30 ## @seealso{pow2, log2} |
3321 | 31 ## @end deftypefn |
2539 | 32 |
5428 | 33 ## Author: KH <Kurt.Hornik@wu-wien.ac.at> |
2539 | 34 ## Created: 7 October 1994 |
35 ## Adapted-By: jwe | |
36 | |
37 function n = nextpow2 (x) | |
3426 | 38 |
2539 | 39 if (nargin != 1) |
6046 | 40 print_usage (); |
2539 | 41 endif |
42 | |
4030 | 43 if (! (isscalar (x) || isvector (x))) |
11472
1740012184f9
Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents:
10793
diff
changeset
|
44 error ("nextpow2: X must be a scalar or a vector"); |
2539 | 45 endif |
2816 | 46 |
47 t = length (x); | |
48 if (t > 1) | |
49 x = t; | |
50 endif | |
3426 | 51 |
2539 | 52 [f, n] = log2 (abs (x)); |
53 if (f == 0.5) | |
54 n = n - 1; | |
55 endif | |
3426 | 56 |
2539 | 57 endfunction |