annotate libinterp/corefcn/betainc.cc @ 20593:c41595061186

eliminate more simple uses of error_state * betainc.cc, file-io.cc, ov-class.cc, ov-struct.cc: Eliminate simple uses of error_state.
author John W. Eaton <jwe@octave.org>
date Mon, 05 Oct 2015 23:09:54 -0400
parents 4f45eaf83908
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3254
28d5f556b8cf [project @ 1999-07-15 16:02:57 by jwe]
jwe
parents:
diff changeset
1 /*
28d5f556b8cf [project @ 1999-07-15 16:02:57 by jwe]
jwe
parents:
diff changeset
2
19731
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 18517
diff changeset
3 Copyright (C) 1997-2015 John W. Eaton
3254
28d5f556b8cf [project @ 1999-07-15 16:02:57 by jwe]
jwe
parents:
diff changeset
4
28d5f556b8cf [project @ 1999-07-15 16:02:57 by jwe]
jwe
parents:
diff changeset
5 This file is part of Octave.
28d5f556b8cf [project @ 1999-07-15 16:02:57 by jwe]
jwe
parents:
diff changeset
6
28d5f556b8cf [project @ 1999-07-15 16:02:57 by jwe]
jwe
parents:
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
28d5f556b8cf [project @ 1999-07-15 16:02:57 by jwe]
jwe
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5823
diff changeset
9 Free Software Foundation; either version 3 of the License, or (at your
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5823
diff changeset
10 option) any later version.
3254
28d5f556b8cf [project @ 1999-07-15 16:02:57 by jwe]
jwe
parents:
diff changeset
11
28d5f556b8cf [project @ 1999-07-15 16:02:57 by jwe]
jwe
parents:
diff changeset
12 Octave is distributed in the hope that it will be useful, but WITHOUT
28d5f556b8cf [project @ 1999-07-15 16:02:57 by jwe]
jwe
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
28d5f556b8cf [project @ 1999-07-15 16:02:57 by jwe]
jwe
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
28d5f556b8cf [project @ 1999-07-15 16:02:57 by jwe]
jwe
parents:
diff changeset
15 for more details.
28d5f556b8cf [project @ 1999-07-15 16:02:57 by jwe]
jwe
parents:
diff changeset
16
28d5f556b8cf [project @ 1999-07-15 16:02:57 by jwe]
jwe
parents:
diff changeset
17 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: 5823
diff changeset
18 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5823
diff changeset
19 <http://www.gnu.org/licenses/>.
3254
28d5f556b8cf [project @ 1999-07-15 16:02:57 by jwe]
jwe
parents:
diff changeset
20
28d5f556b8cf [project @ 1999-07-15 16:02:57 by jwe]
jwe
parents:
diff changeset
21 */
28d5f556b8cf [project @ 1999-07-15 16:02:57 by jwe]
jwe
parents:
diff changeset
22
28d5f556b8cf [project @ 1999-07-15 16:02:57 by jwe]
jwe
parents:
diff changeset
23 #ifdef HAVE_CONFIG_H
28d5f556b8cf [project @ 1999-07-15 16:02:57 by jwe]
jwe
parents:
diff changeset
24 #include <config.h>
28d5f556b8cf [project @ 1999-07-15 16:02:57 by jwe]
jwe
parents:
diff changeset
25 #endif
28d5f556b8cf [project @ 1999-07-15 16:02:57 by jwe]
jwe
parents:
diff changeset
26
28d5f556b8cf [project @ 1999-07-15 16:02:57 by jwe]
jwe
parents:
diff changeset
27 #include "lo-specfun.h"
28d5f556b8cf [project @ 1999-07-15 16:02:57 by jwe]
jwe
parents:
diff changeset
28
15039
e753177cde93 maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents: 14850
diff changeset
29 #include "defun.h"
3254
28d5f556b8cf [project @ 1999-07-15 16:02:57 by jwe]
jwe
parents:
diff changeset
30 #include "error.h"
28d5f556b8cf [project @ 1999-07-15 16:02:57 by jwe]
jwe
parents:
diff changeset
31 #include "gripes.h"
28d5f556b8cf [project @ 1999-07-15 16:02:57 by jwe]
jwe
parents:
diff changeset
32 #include "oct-obj.h"
28d5f556b8cf [project @ 1999-07-15 16:02:57 by jwe]
jwe
parents:
diff changeset
33 #include "utils.h"
28d5f556b8cf [project @ 1999-07-15 16:02:57 by jwe]
jwe
parents:
diff changeset
34
14817
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
35
15039
e753177cde93 maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents: 14850
diff changeset
36 DEFUN (betainc, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
37 "-*- texinfo -*-\n\
3444
fa0d84558faa [project @ 2000-01-17 08:40:39 by jwe]
jwe
parents: 3254
diff changeset
38 @deftypefn {Mapping Function} {} betainc (@var{x}, @var{a}, @var{b})\n\
20207
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19898
diff changeset
39 Compute the regularized incomplete Beta function.\n\
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19898
diff changeset
40 \n\
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19898
diff changeset
41 The regularized incomplete Beta function is defined by\n\
3444
fa0d84558faa [project @ 2000-01-17 08:40:39 by jwe]
jwe
parents: 3254
diff changeset
42 @tex\n\
fa0d84558faa [project @ 2000-01-17 08:40:39 by jwe]
jwe
parents: 3254
diff changeset
43 $$\n\
12658
08f8fc1e9872 betainc.cc: Correctly refer to function as regularized incomplete Beta function.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
44 I (x, a, b) = {1 \\over {B (a, b)}} \\int_0^x t^{(a-z)} (1-t)^{(b-1)} dt.\n\
3444
fa0d84558faa [project @ 2000-01-17 08:40:39 by jwe]
jwe
parents: 3254
diff changeset
45 $$\n\
fa0d84558faa [project @ 2000-01-17 08:40:39 by jwe]
jwe
parents: 3254
diff changeset
46 @end tex\n\
8517
81d6ab3ac93c Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents: 7815
diff changeset
47 @ifnottex\n\
10846
a4f482e66b65 Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents: 10840
diff changeset
48 @c Set example in small font to prevent overfull line\n\
3254
28d5f556b8cf [project @ 1999-07-15 16:02:57 by jwe]
jwe
parents:
diff changeset
49 \n\
3444
fa0d84558faa [project @ 2000-01-17 08:40:39 by jwe]
jwe
parents: 3254
diff changeset
50 @smallexample\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10155
diff changeset
51 @group\n\
14437
62a2ef6c09a4 doc: Correct spacing of integrals in Info version of docstrings.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
52 x\n\
62a2ef6c09a4 doc: Correct spacing of integrals in Info version of docstrings.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
53 1 /\n\
62a2ef6c09a4 doc: Correct spacing of integrals in Info version of docstrings.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
54 betainc (x, a, b) = ----------- | t^(a-1) (1-t)^(b-1) dt.\n\
62a2ef6c09a4 doc: Correct spacing of integrals in Info version of docstrings.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
55 beta (a, b) /\n\
62a2ef6c09a4 doc: Correct spacing of integrals in Info version of docstrings.
Rik <octave@nomad.inbox5.com>
parents: 14360
diff changeset
56 t=0\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10155
diff changeset
57 @end group\n\
3444
fa0d84558faa [project @ 2000-01-17 08:40:39 by jwe]
jwe
parents: 3254
diff changeset
58 @end smallexample\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10155
diff changeset
59 \n\
8517
81d6ab3ac93c Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents: 7815
diff changeset
60 @end ifnottex\n\
3254
28d5f556b8cf [project @ 1999-07-15 16:02:57 by jwe]
jwe
parents:
diff changeset
61 \n\
12776
944cf42c699e doc: small documentation fixes for strftime, betainc
Rik <octave@nomad.inbox5.com>
parents: 12658
diff changeset
62 If @var{x} has more than one component, both @var{a} and @var{b} must be\n\
3444
fa0d84558faa [project @ 2000-01-17 08:40:39 by jwe]
jwe
parents: 3254
diff changeset
63 scalars. If @var{x} is a scalar, @var{a} and @var{b} must be of\n\
fa0d84558faa [project @ 2000-01-17 08:40:39 by jwe]
jwe
parents: 3254
diff changeset
64 compatible dimensions.\n\
14850
cfb64ea5c6a3 doc: Add Seealso links to betainc() docstring
Rik <octave@nomad.inbox5.com>
parents: 14817
diff changeset
65 @seealso{betaincinv, beta, betaln}\n\
3444
fa0d84558faa [project @ 2000-01-17 08:40:39 by jwe]
jwe
parents: 3254
diff changeset
66 @end deftypefn")
3254
28d5f556b8cf [project @ 1999-07-15 16:02:57 by jwe]
jwe
parents:
diff changeset
67 {
28d5f556b8cf [project @ 1999-07-15 16:02:57 by jwe]
jwe
parents:
diff changeset
68 octave_value retval;
28d5f556b8cf [project @ 1999-07-15 16:02:57 by jwe]
jwe
parents:
diff changeset
69
28d5f556b8cf [project @ 1999-07-15 16:02:57 by jwe]
jwe
parents:
diff changeset
70 int nargin = args.length ();
28d5f556b8cf [project @ 1999-07-15 16:02:57 by jwe]
jwe
parents:
diff changeset
71
28d5f556b8cf [project @ 1999-07-15 16:02:57 by jwe]
jwe
parents:
diff changeset
72 if (nargin == 3)
28d5f556b8cf [project @ 1999-07-15 16:02:57 by jwe]
jwe
parents:
diff changeset
73 {
28d5f556b8cf [project @ 1999-07-15 16:02:57 by jwe]
jwe
parents:
diff changeset
74 octave_value x_arg = args(0);
28d5f556b8cf [project @ 1999-07-15 16:02:57 by jwe]
jwe
parents:
diff changeset
75 octave_value a_arg = args(1);
28d5f556b8cf [project @ 1999-07-15 16:02:57 by jwe]
jwe
parents:
diff changeset
76 octave_value b_arg = args(2);
28d5f556b8cf [project @ 1999-07-15 16:02:57 by jwe]
jwe
parents:
diff changeset
77
17861
870f3e12e163 maint: Use phrase "FIXME:" for problem areas in code.
Rik <rik@octave.org>
parents: 17787
diff changeset
78 // FIXME: Can we make a template version of the duplicated code below
19898
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19731
diff changeset
79 if (x_arg.is_single_type () || a_arg.is_single_type ()
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19731
diff changeset
80 || b_arg.is_single_type ())
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
81 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
82 if (x_arg.is_scalar_type ())
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
83 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
84 float x = x_arg.float_value ();
3254
28d5f556b8cf [project @ 1999-07-15 16:02:57 by jwe]
jwe
parents:
diff changeset
85
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
86 if (a_arg.is_scalar_type ())
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
87 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
88 float a = a_arg.float_value ();
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
89
20593
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
90 if (b_arg.is_scalar_type ())
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
91 {
20593
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
92 float b = b_arg.float_value ();
3254
28d5f556b8cf [project @ 1999-07-15 16:02:57 by jwe]
jwe
parents:
diff changeset
93
20593
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
94 retval = betainc (x, a, b);
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
95 }
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
96 else
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
97 {
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
98 Array<float> b = b_arg.float_array_value ();
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
99
20593
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
100 retval = betainc (x, a, b);
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
101 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
102 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
103 else
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
104 {
14815
95b93a728603 Use Array superclass, rather than Matrix or NDArray, for betainc function.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
105 Array<float> a = a_arg.float_array_value ();
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
106
20593
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
107 if (b_arg.is_scalar_type ())
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
108 {
20593
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
109 float b = b_arg.float_value ();
3254
28d5f556b8cf [project @ 1999-07-15 16:02:57 by jwe]
jwe
parents:
diff changeset
110
20593
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
111 retval = betainc (x, a, b);
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
112 }
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
113 else
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
114 {
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
115 Array<float> b = b_arg.float_array_value ();
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
116
20593
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
117 retval = betainc (x, a, b);
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
118 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
119 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
120 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
121 else
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
122 {
14815
95b93a728603 Use Array superclass, rather than Matrix or NDArray, for betainc function.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
123 Array<float> x = x_arg.float_array_value ();
3254
28d5f556b8cf [project @ 1999-07-15 16:02:57 by jwe]
jwe
parents:
diff changeset
124
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
125 if (a_arg.is_scalar_type ())
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
126 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
127 float a = a_arg.float_value ();
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
128
20593
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
129 if (b_arg.is_scalar_type ())
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
130 {
20593
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
131 float b = b_arg.float_value ();
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
132
20593
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
133 retval = betainc (x, a, b);
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
134 }
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
135 else
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
136 {
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
137 Array<float> b = b_arg.float_array_value ();
3254
28d5f556b8cf [project @ 1999-07-15 16:02:57 by jwe]
jwe
parents:
diff changeset
138
20593
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
139 retval = betainc (x, a, b);
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
140 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
141 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
142 else
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
143 {
14815
95b93a728603 Use Array superclass, rather than Matrix or NDArray, for betainc function.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
144 Array<float> a = a_arg.float_array_value ();
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
145
20593
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
146 if (b_arg.is_scalar_type ())
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
147 {
20593
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
148 float b = b_arg.float_value ();
3254
28d5f556b8cf [project @ 1999-07-15 16:02:57 by jwe]
jwe
parents:
diff changeset
149
20593
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
150 retval = betainc (x, a, b);
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
151 }
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
152 else
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
153 {
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
154 Array<float> b = b_arg.float_array_value ();
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
155
20593
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
156 retval = betainc (x, a, b);
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
157 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
158 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
159 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
160 }
3254
28d5f556b8cf [project @ 1999-07-15 16:02:57 by jwe]
jwe
parents:
diff changeset
161 else
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
162 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
163 if (x_arg.is_scalar_type ())
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
164 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
165 double x = x_arg.double_value ();
3254
28d5f556b8cf [project @ 1999-07-15 16:02:57 by jwe]
jwe
parents:
diff changeset
166
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
167 if (a_arg.is_scalar_type ())
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
168 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
169 double a = a_arg.double_value ();
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
170
20593
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
171 if (b_arg.is_scalar_type ())
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
172 {
20593
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
173 double b = b_arg.double_value ();
3254
28d5f556b8cf [project @ 1999-07-15 16:02:57 by jwe]
jwe
parents:
diff changeset
174
20593
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
175 retval = betainc (x, a, b);
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
176 }
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
177 else
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
178 {
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
179 Array<double> b = b_arg.array_value ();
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
180
20593
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
181 retval = betainc (x, a, b);
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
182 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
183 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
184 else
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
185 {
14815
95b93a728603 Use Array superclass, rather than Matrix or NDArray, for betainc function.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
186 Array<double> a = a_arg.array_value ();
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
187
20593
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
188 if (b_arg.is_scalar_type ())
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
189 {
20593
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
190 double b = b_arg.double_value ();
3254
28d5f556b8cf [project @ 1999-07-15 16:02:57 by jwe]
jwe
parents:
diff changeset
191
20593
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
192 retval = betainc (x, a, b);
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
193 }
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
194 else
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
195 {
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
196 Array<double> b = b_arg.array_value ();
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
197
20593
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
198 retval = betainc (x, a, b);
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
199 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
200 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
201 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
202 else
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
203 {
14815
95b93a728603 Use Array superclass, rather than Matrix or NDArray, for betainc function.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
204 Array<double> x = x_arg.array_value ();
3254
28d5f556b8cf [project @ 1999-07-15 16:02:57 by jwe]
jwe
parents:
diff changeset
205
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
206 if (a_arg.is_scalar_type ())
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
207 {
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
208 double a = a_arg.double_value ();
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
209
20593
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
210 if (b_arg.is_scalar_type ())
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
211 {
20593
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
212 double b = b_arg.double_value ();
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
213
20593
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
214 retval = betainc (x, a, b);
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
215 }
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
216 else
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
217 {
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
218 Array<double> b = b_arg.array_value ();
3254
28d5f556b8cf [project @ 1999-07-15 16:02:57 by jwe]
jwe
parents:
diff changeset
219
20593
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
220 retval = betainc (x, a, b);
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
221 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
222 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
223 else
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
224 {
14815
95b93a728603 Use Array superclass, rather than Matrix or NDArray, for betainc function.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
225 Array<double> a = a_arg.array_value ();
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
226
20593
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
227 if (b_arg.is_scalar_type ())
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
228 {
20593
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
229 double b = b_arg.double_value ();
3254
28d5f556b8cf [project @ 1999-07-15 16:02:57 by jwe]
jwe
parents:
diff changeset
230
20593
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
231 retval = betainc (x, a, b);
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
232 }
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
233 else
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
234 {
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
235 Array<double> b = b_arg.array_value ();
7789
82be108cc558 First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents: 7017
diff changeset
236
20593
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
237 retval = betainc (x, a, b);
10154
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
238 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
239 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
240 }
40dfc0c99116 DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents: 9758
diff changeset
241 }
3254
28d5f556b8cf [project @ 1999-07-15 16:02:57 by jwe]
jwe
parents:
diff changeset
242 }
28d5f556b8cf [project @ 1999-07-15 16:02:57 by jwe]
jwe
parents:
diff changeset
243 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5402
diff changeset
244 print_usage ();
3254
28d5f556b8cf [project @ 1999-07-15 16:02:57 by jwe]
jwe
parents:
diff changeset
245
28d5f556b8cf [project @ 1999-07-15 16:02:57 by jwe]
jwe
parents:
diff changeset
246 return retval;
28d5f556b8cf [project @ 1999-07-15 16:02:57 by jwe]
jwe
parents:
diff changeset
247 }
28d5f556b8cf [project @ 1999-07-15 16:02:57 by jwe]
jwe
parents:
diff changeset
248
28d5f556b8cf [project @ 1999-07-15 16:02:57 by jwe]
jwe
parents:
diff changeset
249 /*
14815
95b93a728603 Use Array superclass, rather than Matrix or NDArray, for betainc function.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
250 ## Double precision
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
251 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14437
diff changeset
252 %! a = [1, 1.5, 2, 3];
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14437
diff changeset
253 %! b = [4, 3, 2, 1];
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14437
diff changeset
254 %! v1 = betainc (1,a,b);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14437
diff changeset
255 %! v2 = [1,1,1,1];
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
256 %! x = [.2, .4, .6, .8];
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14437
diff changeset
257 %! v3 = betainc (x, a, b);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14437
diff changeset
258 %! v4 = 1 - betainc (1.-x, b, a);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14437
diff changeset
259 %! assert (v1, v2, sqrt (eps));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14437
diff changeset
260 %! assert (v3, v4, sqrt (eps));
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
261
14815
95b93a728603 Use Array superclass, rather than Matrix or NDArray, for betainc function.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
262 ## Single precision
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
263 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14437
diff changeset
264 %! a = single ([1, 1.5, 2, 3]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14437
diff changeset
265 %! b = single ([4, 3, 2, 1]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14437
diff changeset
266 %! v1 = betainc (1,a,b);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14437
diff changeset
267 %! v2 = single ([1,1,1,1]);
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
268 %! x = single ([.2, .4, .6, .8]);
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14437
diff changeset
269 %! v3 = betainc (x, a, b);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14437
diff changeset
270 %! v4 = 1 - betainc (1.-x, b, a);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14437
diff changeset
271 %! assert (v1, v2, sqrt (eps ("single")));
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14437
diff changeset
272 %! assert (v3, v4, sqrt (eps ("single")));
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
273
14815
95b93a728603 Use Array superclass, rather than Matrix or NDArray, for betainc function.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
274 ## Mixed double/single precision
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
275 %!test
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14437
diff changeset
276 %! a = single ([1, 1.5, 2, 3]);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14437
diff changeset
277 %! b = [4, 3, 2, 1];
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14437
diff changeset
278 %! v1 = betainc (1,a,b);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14437
diff changeset
279 %! v2 = single ([1,1,1,1]);
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
280 %! x = [.2, .4, .6, .8];
14501
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14437
diff changeset
281 %! v3 = betainc (x, a, b);
60e5cf354d80 Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14437
diff changeset
282 %! v4 = 1-betainc (1.-x, b, a);
14815
95b93a728603 Use Array superclass, rather than Matrix or NDArray, for betainc function.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
283 %! assert (v1, v2, sqrt (eps ("single")));
95b93a728603 Use Array superclass, rather than Matrix or NDArray, for betainc function.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
284 %! assert (v3, v4, sqrt (eps ("single")));
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
285
14815
95b93a728603 Use Array superclass, rather than Matrix or NDArray, for betainc function.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
286 %!error betainc ()
95b93a728603 Use Array superclass, rather than Matrix or NDArray, for betainc function.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
287 %!error betainc (1)
95b93a728603 Use Array superclass, rather than Matrix or NDArray, for betainc function.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
288 %!error betainc (1,2)
95b93a728603 Use Array superclass, rather than Matrix or NDArray, for betainc function.
Rik <octave@nomad.inbox5.com>
parents: 14501
diff changeset
289 %!error betainc (1,2,3,4)
7815
a41df65f3f00 Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents: 7789
diff changeset
290 */
14817
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
291
15039
e753177cde93 maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents: 14850
diff changeset
292 DEFUN (betaincinv, args, ,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
293 "-*- texinfo -*-\n\
14817
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
294 @deftypefn {Mapping Function} {} betaincinv (@var{y}, @var{a}, @var{b})\n\
20207
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19898
diff changeset
295 Compute the inverse of the incomplete Beta function.\n\
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19898
diff changeset
296 \n\
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19898
diff changeset
297 The inverse is the value @var{x} such that\n\
14817
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
298 \n\
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
299 @example\n\
20207
4f45eaf83908 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19898
diff changeset
300 @var{y} == betainc (@var{x}, @var{a}, @var{b})\n\
14817
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
301 @end example\n\
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
302 @seealso{betainc, beta, betaln}\n\
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
303 @end deftypefn")
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
304 {
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
305 octave_value retval;
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
306
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
307 int nargin = args.length ();
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
308
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
309 if (nargin == 3)
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
310 {
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
311 octave_value x_arg = args(0);
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
312 octave_value a_arg = args(1);
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
313 octave_value b_arg = args(2);
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
314
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
315 if (x_arg.is_scalar_type ())
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
316 {
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
317 double x = x_arg.double_value ();
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
318
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
319 if (a_arg.is_scalar_type ())
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
320 {
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
321 double a = a_arg.double_value ();
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
322
20593
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
323 if (b_arg.is_scalar_type ())
14817
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
324 {
20593
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
325 double b = b_arg.double_value ();
14817
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
326
20593
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
327 retval = betaincinv (x, a, b);
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
328 }
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
329 else
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
330 {
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
331 Array<double> b = b_arg.array_value ();
14817
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
332
20593
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
333 retval = betaincinv (x, a, b);
14817
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
334 }
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
335 }
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
336 else
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
337 {
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
338 Array<double> a = a_arg.array_value ();
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
339
20593
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
340 if (b_arg.is_scalar_type ())
14817
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
341 {
20593
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
342 double b = b_arg.double_value ();
14817
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
343
20593
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
344 retval = betaincinv (x, a, b);
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
345 }
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
346 else
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
347 {
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
348 Array<double> b = b_arg.array_value ();
14817
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
349
20593
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
350 retval = betaincinv (x, a, b);
14817
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
351 }
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
352 }
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
353 }
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
354 else
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
355 {
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
356 Array<double> x = x_arg.array_value ();
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
357
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
358 if (a_arg.is_scalar_type ())
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
359 {
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
360 double a = a_arg.double_value ();
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
361
20593
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
362 if (b_arg.is_scalar_type ())
14817
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
363 {
20593
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
364 double b = b_arg.double_value ();
14817
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
365
20593
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
366 retval = betaincinv (x, a, b);
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
367 }
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
368 else
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
369 {
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
370 Array<double> b = b_arg.array_value ();
14817
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
371
20593
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
372 retval = betaincinv (x, a, b);
14817
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
373 }
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
374 }
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
375 else
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
376 {
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
377 Array<double> a = a_arg.array_value ();
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
378
20593
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
379 if (b_arg.is_scalar_type ())
14817
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
380 {
20593
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
381 double b = b_arg.double_value ();
14817
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
382
20593
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
383 retval = betaincinv (x, a, b);
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
384 }
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
385 else
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
386 {
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
387 Array<double> b = b_arg.array_value ();
14817
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
388
20593
c41595061186 eliminate more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20207
diff changeset
389 retval = betaincinv (x, a, b);
14817
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
390 }
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
391 }
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
392 }
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
393
14850
cfb64ea5c6a3 doc: Add Seealso links to betainc() docstring
Rik <octave@nomad.inbox5.com>
parents: 14817
diff changeset
394 // FIXME: It would be better to have an algorithm for betaincinv which
cfb64ea5c6a3 doc: Add Seealso links to betainc() docstring
Rik <octave@nomad.inbox5.com>
parents: 14817
diff changeset
395 // accepted float inputs and returned float outputs. As it is, we do
cfb64ea5c6a3 doc: Add Seealso links to betainc() docstring
Rik <octave@nomad.inbox5.com>
parents: 14817
diff changeset
396 // extra work to calculate betaincinv to double precision and then throw
cfb64ea5c6a3 doc: Add Seealso links to betainc() docstring
Rik <octave@nomad.inbox5.com>
parents: 14817
diff changeset
397 // that precision away.
19898
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19731
diff changeset
398 if (x_arg.is_single_type () || a_arg.is_single_type ()
17d647821d61 maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents: 19731
diff changeset
399 || b_arg.is_single_type ())
14817
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
400 {
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
401 retval = Array<float> (retval.array_value ());
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
402 }
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
403 }
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
404 else
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
405 print_usage ();
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
406
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
407 return retval;
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
408 }
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
409
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
410 /*
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
411 %!assert (betaincinv ([0.875 0.6875], [1 2], 3), [0.5 0.5], sqrt (eps))
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
412 %!assert (betaincinv (0.5, 3, 3), 0.5, sqrt (eps))
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
413 %!assert (betaincinv (0.34375, 4, 3), 0.5, sqrt (eps))
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
414 %!assert (betaincinv (0.2265625, 5, 3), 0.5, sqrt (eps))
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
415 %!assert (betaincinv (0.14453125, 6, 3), 0.5, sqrt (eps))
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
416 %!assert (betaincinv (0.08984375, 7, 3), 0.5, sqrt (eps))
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
417 %!assert (betaincinv (0.0546875, 8, 3), 0.5, sqrt (eps))
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
418 %!assert (betaincinv (0.03271484375, 9, 3), 0.5, sqrt (eps))
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
419 %!assert (betaincinv (0.019287109375, 10, 3), 0.5, sqrt (eps))
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
420
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
421 ## Test class single as well
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
422 %!assert (betaincinv ([0.875 0.6875], [1 2], single (3)), [0.5 0.5], sqrt (eps ("single")))
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
423 %!assert (betaincinv (0.5, 3, single (3)), 0.5, sqrt (eps ("single")))
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
424 %!assert (betaincinv (0.34375, 4, single (3)), 0.5, sqrt (eps ("single")))
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
425
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
426 ## Extreme values
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
427 %!assert (betaincinv (0, 42, 42), 0, sqrt (eps))
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
428 %!assert (betaincinv (1, 42, 42), 1, sqrt (eps))
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
429
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
430 %!error betaincinv ()
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
431 %!error betaincinv (1, 2)
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
432 */
67897baaa05f Adapt implementation of betaincinv to Octave.
Rik <octave@nomad.inbox5.com>
parents: 14815
diff changeset
433