annotate scripts/specfun/pow2.m @ 29359:7854d5752dd2

maint: merge stable to default.
author John W. Eaton <jwe@octave.org>
date Wed, 10 Feb 2021 10:10:40 -0500
parents d8318c12d903 0a5b15007766
children 796f54d4ddbf
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ########################################################################
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 ##
29358
0a5b15007766 update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 27985
diff changeset
3 ## Copyright (C) 1995-2021 The Octave Project Developers
27918
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
4 ##
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
5 ## See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 ## distribution or <https://octave.org/copyright/>.
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3407
diff changeset
7 ##
3922
38c61cbf086c [project @ 2002-05-01 06:48:35 by jwe]
jwe
parents: 3456
diff changeset
8 ## This file is part of Octave.
38c61cbf086c [project @ 2002-05-01 06:48:35 by jwe]
jwe
parents: 3456
diff changeset
9 ##
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
10 ## Octave is free software: you can redistribute it and/or modify it
3922
38c61cbf086c [project @ 2002-05-01 06:48:35 by jwe]
jwe
parents: 3456
diff changeset
11 ## under the terms of the GNU General Public License as published by
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
12 ## the Free Software Foundation, either version 3 of the License, or
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
13 ## (at your option) any later version.
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3407
diff changeset
14 ##
3922
38c61cbf086c [project @ 2002-05-01 06:48:35 by jwe]
jwe
parents: 3456
diff changeset
15 ## Octave is distributed in the hope that it will be useful, but
2537
80b982e7f4b1 [project @ 1996-11-19 21:15:06 by jwe]
jwe
parents:
diff changeset
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
18 ## GNU General Public License for more details.
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3407
diff changeset
19 ##
2537
80b982e7f4b1 [project @ 1996-11-19 21:15:06 by jwe]
jwe
parents:
diff changeset
20 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
21 ## along with Octave; see the file COPYING. If not, see
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
22 ## <https://www.gnu.org/licenses/>.
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
23 ##
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 ########################################################################
2537
80b982e7f4b1 [project @ 1996-11-19 21:15:06 by jwe]
jwe
parents:
diff changeset
25
3321
6923abb04e16 [project @ 1999-10-26 18:15:30 by jwe]
jwe
parents: 2537
diff changeset
26 ## -*- texinfo -*-
20852
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 19697
diff changeset
27 ## @deftypefn {} {} pow2 (@var{x})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 19697
diff changeset
28 ## @deftypefnx {} {} pow2 (@var{f}, @var{e})
19102
bb20384acf7b doc: Overhaul documentation for some functions in specfun/ dir.
Rik <rik@octave.org>
parents: 17744
diff changeset
29 ## With one input argument, compute
3321
6923abb04e16 [project @ 1999-10-26 18:15:30 by jwe]
jwe
parents: 2537
diff changeset
30 ## @tex
9167
1231b1762a9a Simplify TeXinfo and eliminate use of @iftex in arith.txi
Rik <rdrider0-list@yahoo.com>
parents: 9141
diff changeset
31 ## $2^x$
3321
6923abb04e16 [project @ 1999-10-26 18:15:30 by jwe]
jwe
parents: 2537
diff changeset
32 ## @end tex
8517
81d6ab3ac93c Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents: 7742
diff changeset
33 ## @ifnottex
9167
1231b1762a9a Simplify TeXinfo and eliminate use of @iftex in arith.txi
Rik <rdrider0-list@yahoo.com>
parents: 9141
diff changeset
34 ## 2 .^ x
8517
81d6ab3ac93c Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents: 7742
diff changeset
35 ## @end ifnottex
9141
c1fff751b5a8 Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
36 ## for each element of @var{x}.
c1fff751b5a8 Update section 17.1 (Utility Functions) of arith.txi
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
37 ##
19102
bb20384acf7b doc: Overhaul documentation for some functions in specfun/ dir.
Rik <rik@octave.org>
parents: 17744
diff changeset
38 ## With two input arguments, return
3321
6923abb04e16 [project @ 1999-10-26 18:15:30 by jwe]
jwe
parents: 2537
diff changeset
39 ## @tex
9167
1231b1762a9a Simplify TeXinfo and eliminate use of @iftex in arith.txi
Rik <rdrider0-list@yahoo.com>
parents: 9141
diff changeset
40 ## $f \cdot 2^e$.
3321
6923abb04e16 [project @ 1999-10-26 18:15:30 by jwe]
jwe
parents: 2537
diff changeset
41 ## @end tex
8517
81d6ab3ac93c Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents: 7742
diff changeset
42 ## @ifnottex
9167
1231b1762a9a Simplify TeXinfo and eliminate use of @iftex in arith.txi
Rik <rdrider0-list@yahoo.com>
parents: 9141
diff changeset
43 ## f .* (2 .^ e).
8517
81d6ab3ac93c Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents: 7742
diff changeset
44 ## @end ifnottex
19102
bb20384acf7b doc: Overhaul documentation for some functions in specfun/ dir.
Rik <rik@octave.org>
parents: 17744
diff changeset
45 ## @seealso{log2, nextpow2, power}
3321
6923abb04e16 [project @ 1999-10-26 18:15:30 by jwe]
jwe
parents: 2537
diff changeset
46 ## @end deftypefn
2537
80b982e7f4b1 [project @ 1996-11-19 21:15:06 by jwe]
jwe
parents:
diff changeset
47
80b982e7f4b1 [project @ 1996-11-19 21:15:06 by jwe]
jwe
parents:
diff changeset
48 function y = pow2 (f, e)
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3407
diff changeset
49
28789
28de41192f3c Eliminate unneeded verification of nargin, nargout in m-files.
Rik <rik@octave.org>
parents: 27985
diff changeset
50 if (nargin < 1)
28de41192f3c Eliminate unneeded verification of nargin, nargout in m-files.
Rik <rik@octave.org>
parents: 27985
diff changeset
51 print_usage ();
28de41192f3c Eliminate unneeded verification of nargin, nargout in m-files.
Rik <rik@octave.org>
parents: 27985
diff changeset
52 endif
28de41192f3c Eliminate unneeded verification of nargin, nargout in m-files.
Rik <rik@octave.org>
parents: 27985
diff changeset
53
2537
80b982e7f4b1 [project @ 1996-11-19 21:15:06 by jwe]
jwe
parents:
diff changeset
54 if (nargin == 1)
80b982e7f4b1 [project @ 1996-11-19 21:15:06 by jwe]
jwe
parents:
diff changeset
55 y = 2 .^ f;
28789
28de41192f3c Eliminate unneeded verification of nargin, nargout in m-files.
Rik <rik@octave.org>
parents: 27985
diff changeset
56 else
2537
80b982e7f4b1 [project @ 1996-11-19 21:15:06 by jwe]
jwe
parents:
diff changeset
57 y = f .* (2 .^ e);
80b982e7f4b1 [project @ 1996-11-19 21:15:06 by jwe]
jwe
parents:
diff changeset
58 endif
80b982e7f4b1 [project @ 1996-11-19 21:15:06 by jwe]
jwe
parents:
diff changeset
59
80b982e7f4b1 [project @ 1996-11-19 21:15:06 by jwe]
jwe
parents:
diff changeset
60 endfunction
7385
8b7b4f58199f [project @ 2008-01-15 20:49:09 by jwe]
jwe
parents: 7017
diff changeset
61
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
62
7385
8b7b4f58199f [project @ 2008-01-15 20:49:09 by jwe]
jwe
parents: 7017
diff changeset
63 %!test
8b7b4f58199f [project @ 2008-01-15 20:49:09 by jwe]
jwe
parents: 7017
diff changeset
64 %! x = [3, 0, -3];
8b7b4f58199f [project @ 2008-01-15 20:49:09 by jwe]
jwe
parents: 7017
diff changeset
65 %! v = [8, 1, .125];
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
66 %! assert (pow2 (x), v, sqrt (eps));
7385
8b7b4f58199f [project @ 2008-01-15 20:49:09 by jwe]
jwe
parents: 7017
diff changeset
67
8b7b4f58199f [project @ 2008-01-15 20:49:09 by jwe]
jwe
parents: 7017
diff changeset
68 %!test
8b7b4f58199f [project @ 2008-01-15 20:49:09 by jwe]
jwe
parents: 7017
diff changeset
69 %! x = [3, 0, -3, 4, 0, -4, 5, 0, -5];
8b7b4f58199f [project @ 2008-01-15 20:49:09 by jwe]
jwe
parents: 7017
diff changeset
70 %! y = [-2, -2, -2, 1, 1, 1, 3, 3, 3];
8b7b4f58199f [project @ 2008-01-15 20:49:09 by jwe]
jwe
parents: 7017
diff changeset
71 %! z = x .* (2 .^ y);
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
72 %! assert (pow2 (x,y), z, sqrt (eps));
7385
8b7b4f58199f [project @ 2008-01-15 20:49:09 by jwe]
jwe
parents: 7017
diff changeset
73
28886
d8318c12d903 test: remove unnecessary BIST tests in m-files checking for excessive number of inputs.
Rik <rik@octave.org>
parents: 28789
diff changeset
74 %!error <Invalid call> pow2 ()