Mercurial > octave-nkf
annotate scripts/specfun/realpow.m @ 20595:c1a6c31ac29a
eliminate more simple uses of error_state
* ov-classdef.cc: Eliminate simple uses of error_state.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 06 Oct 2015 00:20:02 -0400 |
parents | 4197fc428c7d |
children |
rev | line source |
---|---|
19731
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19136
diff
changeset
|
1 ## Copyright (C) 2008-2015 David Bateman |
7621
4682dda22527
Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
2 ## |
4682dda22527
Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
3 ## This file is part of Octave. |
4682dda22527
Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
4 ## |
4682dda22527
Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
5 ## Octave is free software; you can redistribute it and/or modify it |
4682dda22527
Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
6 ## under the terms of the GNU General Public License as published by |
4682dda22527
Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
7 ## the Free Software Foundation; either version 3 of the License, or (at |
4682dda22527
Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
8 ## your option) any later version. |
4682dda22527
Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
9 ## |
4682dda22527
Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
10 ## Octave is distributed in the hope that it will be useful, but |
4682dda22527
Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
4682dda22527
Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
4682dda22527
Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
13 ## General Public License for more details. |
4682dda22527
Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
14 ## |
4682dda22527
Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
15 ## You should have received a copy of the GNU General Public License |
4682dda22527
Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
16 ## along with Octave; see the file COPYING. If not, see |
4682dda22527
Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
17 ## <http://www.gnu.org/licenses/>. |
4682dda22527
Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
18 |
4682dda22527
Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
19 ## -*- texinfo -*- |
4682dda22527
Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
20 ## @deftypefn {Function File} {} realpow (@var{x}, @var{y}) |
19136
bb20384acf7b
doc: Overhaul documentation for some functions in specfun/ dir.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
21 ## Compute the real-valued, element-by-element power operator. |
bb20384acf7b
doc: Overhaul documentation for some functions in specfun/ dir.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
22 ## |
bb20384acf7b
doc: Overhaul documentation for some functions in specfun/ dir.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
23 ## This is equivalent to @w{@code{@var{x} .^ @var{y}}}, except that |
bb20384acf7b
doc: Overhaul documentation for some functions in specfun/ dir.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
24 ## @code{realpow} reports an error if any return value is complex. |
bb20384acf7b
doc: Overhaul documentation for some functions in specfun/ dir.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
25 ## @seealso{power, reallog, realsqrt} |
7621
4682dda22527
Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
26 ## @end deftypefn |
4682dda22527
Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
27 |
4682dda22527
Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
28 function z = realpow (x, y) |
19136
bb20384acf7b
doc: Overhaul documentation for some functions in specfun/ dir.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
29 |
7621
4682dda22527
Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
30 if (nargin != 2) |
4682dda22527
Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
31 print_usage (); |
4682dda22527
Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
32 endif |
19136
bb20384acf7b
doc: Overhaul documentation for some functions in specfun/ dir.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
33 |
bb20384acf7b
doc: Overhaul documentation for some functions in specfun/ dir.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
34 z = x .^ y; |
bb20384acf7b
doc: Overhaul documentation for some functions in specfun/ dir.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
35 if (iscomplex (z)) |
bb20384acf7b
doc: Overhaul documentation for some functions in specfun/ dir.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
36 error ("realpow: produced complex result"); |
bb20384acf7b
doc: Overhaul documentation for some functions in specfun/ dir.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
37 endif |
bb20384acf7b
doc: Overhaul documentation for some functions in specfun/ dir.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
38 |
7621
4682dda22527
Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
39 endfunction |
4682dda22527
Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
40 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
41 |
19136
bb20384acf7b
doc: Overhaul documentation for some functions in specfun/ dir.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
42 %!assert (realpow (1:10, 0.5:0.5:5), power (1:10, 0.5:0.5:5)) |
bb20384acf7b
doc: Overhaul documentation for some functions in specfun/ dir.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
43 %!assert (realpow (1:10, 0.5:0.5:5), [1:10] .^ [0.5:0.5:5]) |
7621
4682dda22527
Add the reallog, realsqrt and realpow functions
David Bateman <dbateman@free.fr>
parents:
diff
changeset
|
44 %!test |
19136
bb20384acf7b
doc: Overhaul documentation for some functions in specfun/ dir.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
45 %! x = rand (10, 10); |
bb20384acf7b
doc: Overhaul documentation for some functions in specfun/ dir.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
46 %! y = randn (10, 10); |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
47 %! assert (x.^y, realpow (x,y)); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
48 %!assert (realpow (1i,2), -1) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
49 |
19136
bb20384acf7b
doc: Overhaul documentation for some functions in specfun/ dir.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
50 %!error realpow () |
bb20384acf7b
doc: Overhaul documentation for some functions in specfun/ dir.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
51 %!error realpow (1) |
bb20384acf7b
doc: Overhaul documentation for some functions in specfun/ dir.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
52 %!error realpow (1,2,3) |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
53 %!error <produced complex result> realpow (-1, 1/2) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
54 |