changelog shortlog tags changeset files revisions annotate raw

scripts/specfun/pow2.m

changeset 10289: 4b124317dc38
parent:c1fff751b5a8
author: John W. Eaton <jwe@octave.org>
date: Tue Feb 09 20:58:55 2010 -0500 (30 minutes ago)
permissions: -rw-r--r--
description: base_properties::set_children: account for hidden children
1## Copyright (C) 1995, 1996, 1999, 2000, 2002, 2004, 2005, 2006, 2007,
2## 2008, 2009 Kurt Hornik
3##
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
8## the Free Software Foundation; either version 3 of the License, or (at
9## your option) any later version.
10##
11## Octave is distributed in the hope that it will be useful, but
12## WITHOUT ANY WARRANTY; without even the implied warranty of
13## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14## General Public License for more details.
15##
16## You should have received a copy of the GNU General Public License
17## along with Octave; see the file COPYING. If not, see
18## <http://www.gnu.org/licenses/>.
19
20## -*- texinfo -*-
21## @deftypefn {Mapping Function} {} pow2 (@var{x})
22## @deftypefnx {Mapping Function} {} pow2 (@var{f}, @var{e})
23## With one argument, computes
24## @tex
25## $2^x$
26## @end tex
27## @ifnottex
28## 2 .^ x
29## @end ifnottex
30## for each element of @var{x}.
31##
32## With two arguments, returns
33## @tex
34## $f \cdot 2^e$.
35## @end tex
36## @ifnottex
37## f .* (2 .^ e).
38## @end ifnottex
39## @seealso{log2, nextpow2}
40## @end deftypefn
41
42## Author: AW <Andreas.Weingessel@ci.tuwien.ac.at>
43## Created: 17 October 1994
44## Adapted-By: jwe
45
46function y = pow2 (f, e)
47
48 if (nargin == 1)
49 y = 2 .^ f;
50 elseif (nargin == 2)
51 y = f .* (2 .^ e);
52 else
53 print_usage ();
54 endif
55
56endfunction
57
58%!test
59%! x = [3, 0, -3];
60%! v = [8, 1, .125];
61%! assert(all (abs (pow2 (x) - v) < sqrt (eps)));
62
63%!test
64%! x = [3, 0, -3, 4, 0, -4, 5, 0, -5];
65%! y = [-2, -2, -2, 1, 1, 1, 3, 3, 3];
66%! z = x .* (2 .^ y);
67%! assert(all (abs (pow2 (x,y) - z) < sqrt (eps)));
68
69%!error pow2();
70