Mercurial > hg > octave-nkf
annotate scripts/general/nextpow2.m @ 9665:1dba57e9d08d
use blas_trans_type for xgemm
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Sat, 26 Sep 2009 10:41:07 +0200 |
parents | 1231b1762a9a |
children | be55736a0783 |
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}) | |
9141
c1fff751b5a8
Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
22 ## If @var{x} is a scalar, return the first integer @var{n} such that |
3321 | 23 ## @tex |
9167
1231b1762a9a
Simplify TeXinfo and eliminate use of @iftex in arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9141
diff
changeset
|
24 ## $2^n \ge |x|$. |
3321 | 25 ## @end tex |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7017
diff
changeset
|
26 ## @ifnottex |
9167
1231b1762a9a
Simplify TeXinfo and eliminate use of @iftex in arith.txi
Rik <rdrider0-list@yahoo.com>
parents:
9141
diff
changeset
|
27 ## 2^n >= abs (x). |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7017
diff
changeset
|
28 ## @end ifnottex |
3426 | 29 ## |
3321 | 30 ## 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
|
31 ## @seealso{pow2, log2} |
3321 | 32 ## @end deftypefn |
2539 | 33 |
5428 | 34 ## Author: KH <Kurt.Hornik@wu-wien.ac.at> |
2539 | 35 ## Created: 7 October 1994 |
36 ## Adapted-By: jwe | |
37 | |
38 function n = nextpow2 (x) | |
3426 | 39 |
2539 | 40 if (nargin != 1) |
6046 | 41 print_usage (); |
2539 | 42 endif |
43 | |
4030 | 44 if (! (isscalar (x) || isvector (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 | |
3426 | 52 |
2539 | 53 [f, n] = log2 (abs (x)); |
54 if (f == 0.5) | |
55 n = n - 1; | |
56 endif | |
3426 | 57 |
2539 | 58 endfunction |