Mercurial > hg > octave-lojdl
annotate src/DLD-FUNCTIONS/gammainc.cc @ 11415:e7ed20f87e82
Add @tex blocks to gammainc and legendre docstrings.
author | Michael Godfrey <godfrey@isl.stanford.edu> |
---|---|
date | Sun, 26 Dec 2010 21:28:20 -0800 |
parents | 89f4d7e294cc |
children | fd0a3ac60b0e |
rev | line source |
---|---|
3254 | 1 /* |
2 | |
8920 | 3 Copyright (C) 1997, 1999, 2000, 2004, 2005, 2006, 2007, 2008, |
4 2009 John W. Eaton | |
3254 | 5 |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
3254 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
3254 | 21 |
22 */ | |
23 | |
24 #ifdef HAVE_CONFIG_H | |
25 #include <config.h> | |
26 #endif | |
27 | |
28 #include "lo-specfun.h" | |
29 | |
30 #include "defun-dld.h" | |
31 #include "error.h" | |
32 #include "gripes.h" | |
33 #include "oct-obj.h" | |
34 #include "utils.h" | |
35 | |
36 DEFUN_DLD (gammainc, args, , | |
3548 | 37 "-*- texinfo -*-\n\ |
10840 | 38 @deftypefn {Mapping Function} {} gammainc (@var{x}, @var{a})\n\ |
10698
fa00ccf7b1f9
Implementary complementary incomplete gamma function (bug #30088)
David Bateman <dbateman@free.fr>
parents:
10155
diff
changeset
|
39 @deftypefnx {Mapping Function} {} gammainc (@var{x}, @var{a}, \"lower\")\n\ |
fa00ccf7b1f9
Implementary complementary incomplete gamma function (bug #30088)
David Bateman <dbateman@free.fr>
parents:
10155
diff
changeset
|
40 @deftypefnx {Mapping Function} {} gammainc (@var{x}, @var{a}, \"upper\")\n\ |
5517 | 41 Compute the normalized incomplete gamma function,\n\ |
3444 | 42 @tex\n\ |
43 $$\n\ | |
11415
e7ed20f87e82
Add @tex blocks to gammainc and legendre docstrings.
Michael Godfrey <godfrey@isl.stanford.edu>
parents:
10840
diff
changeset
|
44 \\gamma (x, a) = {1 \\over {\\Gamma (a)}}\\displaystyle{\\int_0^x t^{a-1} e^{-t} dt}\n\ |
3444 | 45 $$\n\ |
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\ |
3254 | 48 \n\ |
11415
e7ed20f87e82
Add @tex blocks to gammainc and legendre docstrings.
Michael Godfrey <godfrey@isl.stanford.edu>
parents:
10840
diff
changeset
|
49 @example\n\ |
10840 | 50 @group\n\ |
11415
e7ed20f87e82
Add @tex blocks to gammainc and legendre docstrings.
Michael Godfrey <godfrey@isl.stanford.edu>
parents:
10840
diff
changeset
|
51 x\n\ |
e7ed20f87e82
Add @tex blocks to gammainc and legendre docstrings.
Michael Godfrey <godfrey@isl.stanford.edu>
parents:
10840
diff
changeset
|
52 1 /\n\ |
3683 | 53 gammainc (x, a) = --------- | exp (-t) t^(a-1) dt\n\ |
11415
e7ed20f87e82
Add @tex blocks to gammainc and legendre docstrings.
Michael Godfrey <godfrey@isl.stanford.edu>
parents:
10840
diff
changeset
|
54 gamma (a) /\n\ |
e7ed20f87e82
Add @tex blocks to gammainc and legendre docstrings.
Michael Godfrey <godfrey@isl.stanford.edu>
parents:
10840
diff
changeset
|
55 t=0\n\ |
10840 | 56 @end group\n\ |
11415
e7ed20f87e82
Add @tex blocks to gammainc and legendre docstrings.
Michael Godfrey <godfrey@isl.stanford.edu>
parents:
10840
diff
changeset
|
57 @end example\n\ |
5517 | 58 \n\ |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
7815
diff
changeset
|
59 @end ifnottex\n\ |
5517 | 60 with the limiting value of 1 as @var{x} approaches infinity.\n\ |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
61 The standard notation is @math{P(a,x)}, e.g., Abramowitz and Stegun (6.5.1).\n\ |
3254 | 62 \n\ |
3683 | 63 If @var{a} is scalar, then @code{gammainc (@var{x}, @var{a})} is returned\n\ |
3444 | 64 for each element of @var{x} and vice versa.\n\ |
65 \n\ | |
3683 | 66 If neither @var{x} nor @var{a} is scalar, the sizes of @var{x} and\n\ |
11415
e7ed20f87e82
Add @tex blocks to gammainc and legendre docstrings.
Michael Godfrey <godfrey@isl.stanford.edu>
parents:
10840
diff
changeset
|
67 @var{a} must agree, and @code{gammainc} is applied element-by-element.\n\ |
10698
fa00ccf7b1f9
Implementary complementary incomplete gamma function (bug #30088)
David Bateman <dbateman@free.fr>
parents:
10155
diff
changeset
|
68 \n\ |
fa00ccf7b1f9
Implementary complementary incomplete gamma function (bug #30088)
David Bateman <dbateman@free.fr>
parents:
10155
diff
changeset
|
69 By default the incomplete gamma function integrated from 0 to @var{x} is\n\ |
10711
fbd7843974fa
Periodic grammar check of documentation files to ensure common format.
Rik <octave@nomad.inbox5.com>
parents:
10700
diff
changeset
|
70 computed. If \"upper\" is given then the complementary function integrated\n\ |
11415
e7ed20f87e82
Add @tex blocks to gammainc and legendre docstrings.
Michael Godfrey <godfrey@isl.stanford.edu>
parents:
10840
diff
changeset
|
71 from @var{x} to infinity is calculated. It should be noted that\n\ |
10698
fa00ccf7b1f9
Implementary complementary incomplete gamma function (bug #30088)
David Bateman <dbateman@free.fr>
parents:
10155
diff
changeset
|
72 \n\ |
fa00ccf7b1f9
Implementary complementary incomplete gamma function (bug #30088)
David Bateman <dbateman@free.fr>
parents:
10155
diff
changeset
|
73 @example\n\ |
11415
e7ed20f87e82
Add @tex blocks to gammainc and legendre docstrings.
Michael Godfrey <godfrey@isl.stanford.edu>
parents:
10840
diff
changeset
|
74 gammainc (@var{x}, @var{a}) @equiv{} 1 - gammainc (@var{x}, @var{a}, \"upper\")\n\ |
10698
fa00ccf7b1f9
Implementary complementary incomplete gamma function (bug #30088)
David Bateman <dbateman@free.fr>
parents:
10155
diff
changeset
|
75 @end example\n\ |
5642 | 76 @seealso{gamma, lgamma}\n\ |
77 @end deftypefn") | |
3254 | 78 { |
79 octave_value retval; | |
10698
fa00ccf7b1f9
Implementary complementary incomplete gamma function (bug #30088)
David Bateman <dbateman@free.fr>
parents:
10155
diff
changeset
|
80 bool lower = true; |
3254 | 81 |
82 int nargin = args.length (); | |
83 | |
10698
fa00ccf7b1f9
Implementary complementary incomplete gamma function (bug #30088)
David Bateman <dbateman@free.fr>
parents:
10155
diff
changeset
|
84 if (nargin == 3) |
fa00ccf7b1f9
Implementary complementary incomplete gamma function (bug #30088)
David Bateman <dbateman@free.fr>
parents:
10155
diff
changeset
|
85 { |
fa00ccf7b1f9
Implementary complementary incomplete gamma function (bug #30088)
David Bateman <dbateman@free.fr>
parents:
10155
diff
changeset
|
86 if (args(2).is_string ()) |
fa00ccf7b1f9
Implementary complementary incomplete gamma function (bug #30088)
David Bateman <dbateman@free.fr>
parents:
10155
diff
changeset
|
87 { |
fa00ccf7b1f9
Implementary complementary incomplete gamma function (bug #30088)
David Bateman <dbateman@free.fr>
parents:
10155
diff
changeset
|
88 std::string s = args(2).string_value (); |
fa00ccf7b1f9
Implementary complementary incomplete gamma function (bug #30088)
David Bateman <dbateman@free.fr>
parents:
10155
diff
changeset
|
89 std::transform (s.begin (), s.end (), s.begin (), tolower); |
fa00ccf7b1f9
Implementary complementary incomplete gamma function (bug #30088)
David Bateman <dbateman@free.fr>
parents:
10155
diff
changeset
|
90 if (s == "upper") |
fa00ccf7b1f9
Implementary complementary incomplete gamma function (bug #30088)
David Bateman <dbateman@free.fr>
parents:
10155
diff
changeset
|
91 lower = false; |
fa00ccf7b1f9
Implementary complementary incomplete gamma function (bug #30088)
David Bateman <dbateman@free.fr>
parents:
10155
diff
changeset
|
92 else if (s != "lower") |
fa00ccf7b1f9
Implementary complementary incomplete gamma function (bug #30088)
David Bateman <dbateman@free.fr>
parents:
10155
diff
changeset
|
93 error ("expecting third argument to be \"lower\" or \"upper\""); |
fa00ccf7b1f9
Implementary complementary incomplete gamma function (bug #30088)
David Bateman <dbateman@free.fr>
parents:
10155
diff
changeset
|
94 } |
fa00ccf7b1f9
Implementary complementary incomplete gamma function (bug #30088)
David Bateman <dbateman@free.fr>
parents:
10155
diff
changeset
|
95 else |
fa00ccf7b1f9
Implementary complementary incomplete gamma function (bug #30088)
David Bateman <dbateman@free.fr>
parents:
10155
diff
changeset
|
96 error ("expecting third argument to be \"lower\" or \"upper\""); |
fa00ccf7b1f9
Implementary complementary incomplete gamma function (bug #30088)
David Bateman <dbateman@free.fr>
parents:
10155
diff
changeset
|
97 |
fa00ccf7b1f9
Implementary complementary incomplete gamma function (bug #30088)
David Bateman <dbateman@free.fr>
parents:
10155
diff
changeset
|
98 } |
fa00ccf7b1f9
Implementary complementary incomplete gamma function (bug #30088)
David Bateman <dbateman@free.fr>
parents:
10155
diff
changeset
|
99 |
fa00ccf7b1f9
Implementary complementary incomplete gamma function (bug #30088)
David Bateman <dbateman@free.fr>
parents:
10155
diff
changeset
|
100 if (!error_state && nargin >= 2 && nargin <= 3) |
3254 | 101 { |
102 octave_value x_arg = args(0); | |
103 octave_value a_arg = args(1); | |
104 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
105 // FIXME Can we make a template version of the duplicated code below |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
106 if (x_arg.is_single_type () || a_arg.is_single_type ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
107 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
108 if (x_arg.is_scalar_type ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
109 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
110 float x = x_arg.float_value (); |
3254 | 111 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
112 if (! error_state) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
113 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
114 if (a_arg.is_scalar_type ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
115 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
116 float a = a_arg.float_value (); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
117 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
118 if (! error_state) |
10698
fa00ccf7b1f9
Implementary complementary incomplete gamma function (bug #30088)
David Bateman <dbateman@free.fr>
parents:
10155
diff
changeset
|
119 retval = lower ? gammainc (x, a) |
fa00ccf7b1f9
Implementary complementary incomplete gamma function (bug #30088)
David Bateman <dbateman@free.fr>
parents:
10155
diff
changeset
|
120 : static_cast<float>(1) - gammainc (x, a); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
121 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
122 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
123 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
124 FloatNDArray a = a_arg.float_array_value (); |
3254 | 125 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
126 if (! error_state) |
10698
fa00ccf7b1f9
Implementary complementary incomplete gamma function (bug #30088)
David Bateman <dbateman@free.fr>
parents:
10155
diff
changeset
|
127 retval = lower ? gammainc (x, a) |
fa00ccf7b1f9
Implementary complementary incomplete gamma function (bug #30088)
David Bateman <dbateman@free.fr>
parents:
10155
diff
changeset
|
128 : static_cast<float>(1) - gammainc (x, a); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
129 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
130 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
131 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
132 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
133 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
134 FloatNDArray x = x_arg.float_array_value (); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
135 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
136 if (! error_state) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
137 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
138 if (a_arg.is_scalar_type ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
139 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
140 float a = a_arg.float_value (); |
3254 | 141 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
142 if (! error_state) |
10698
fa00ccf7b1f9
Implementary complementary incomplete gamma function (bug #30088)
David Bateman <dbateman@free.fr>
parents:
10155
diff
changeset
|
143 retval = lower ? gammainc (x, a) |
fa00ccf7b1f9
Implementary complementary incomplete gamma function (bug #30088)
David Bateman <dbateman@free.fr>
parents:
10155
diff
changeset
|
144 : static_cast<float>(1) - gammainc (x, a); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
145 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
146 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
147 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
148 FloatNDArray a = a_arg.float_array_value (); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
149 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
150 if (! error_state) |
10698
fa00ccf7b1f9
Implementary complementary incomplete gamma function (bug #30088)
David Bateman <dbateman@free.fr>
parents:
10155
diff
changeset
|
151 retval = lower ? gammainc (x, a) |
fa00ccf7b1f9
Implementary complementary incomplete gamma function (bug #30088)
David Bateman <dbateman@free.fr>
parents:
10155
diff
changeset
|
152 : static_cast<float>(1) - gammainc (x, a); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
153 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
154 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
155 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
156 } |
3254 | 157 else |
10154
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 if (x_arg.is_scalar_type ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
160 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
161 double x = x_arg.double_value (); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
162 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
163 if (! error_state) |
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 if (a_arg.is_scalar_type ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
166 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
167 double a = a_arg.double_value (); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
168 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
169 if (! error_state) |
10698
fa00ccf7b1f9
Implementary complementary incomplete gamma function (bug #30088)
David Bateman <dbateman@free.fr>
parents:
10155
diff
changeset
|
170 retval = lower ? gammainc (x, a) : 1. - gammainc (x, a); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
171 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
172 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
173 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
174 NDArray a = a_arg.array_value (); |
3254 | 175 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
176 if (! error_state) |
10698
fa00ccf7b1f9
Implementary complementary incomplete gamma function (bug #30088)
David Bateman <dbateman@free.fr>
parents:
10155
diff
changeset
|
177 retval = lower ? gammainc (x, a) : 1. - gammainc (x, a); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
178 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
179 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
180 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
181 else |
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 NDArray x = x_arg.array_value (); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
184 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
185 if (! error_state) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
186 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
187 if (a_arg.is_scalar_type ()) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
188 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
189 double a = a_arg.double_value (); |
3254 | 190 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
191 if (! error_state) |
10698
fa00ccf7b1f9
Implementary complementary incomplete gamma function (bug #30088)
David Bateman <dbateman@free.fr>
parents:
10155
diff
changeset
|
192 retval = lower ? gammainc (x, a) : 1. - gammainc (x, a); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
193 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
194 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
195 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
196 NDArray a = a_arg.array_value (); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
197 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
198 if (! error_state) |
10698
fa00ccf7b1f9
Implementary complementary incomplete gamma function (bug #30088)
David Bateman <dbateman@free.fr>
parents:
10155
diff
changeset
|
199 retval = lower ? gammainc (x, a) : 1. - gammainc (x, a); |
10154
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 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9758
diff
changeset
|
203 } |
3254 | 204 } |
205 else | |
5823 | 206 print_usage (); |
3254 | 207 |
208 return retval; | |
209 } | |
210 | |
211 /* | |
7815
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
212 |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
213 %!test |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
214 %! a = [.5 .5 .5 .5 .5]; |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
215 %! x = [0 1 2 3 4]; |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
216 %! v1 = sqrt(pi)*erf(x)./gamma(a); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
217 %! v3 = gammainc(x.*x,a); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
218 %! assert(v1, v3, sqrt(eps)); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
219 |
10698
fa00ccf7b1f9
Implementary complementary incomplete gamma function (bug #30088)
David Bateman <dbateman@free.fr>
parents:
10155
diff
changeset
|
220 %!assert (gammainc(0:4,0.5,"upper"), 1-gammainc(0:4,0.5),1e-10) |
fa00ccf7b1f9
Implementary complementary incomplete gamma function (bug #30088)
David Bateman <dbateman@free.fr>
parents:
10155
diff
changeset
|
221 |
7815
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
222 %!test |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
223 %! a = single ([.5 .5 .5 .5 .5]); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
224 %! x = single([0 1 2 3 4]); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
225 %! v1 = sqrt(pi('single'))*erf(x)./gamma(a); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
226 %! v3 = gammainc(x.*x,a); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
227 %! assert(v1, v3, sqrt(eps('single'))); |
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
228 |
10698
fa00ccf7b1f9
Implementary complementary incomplete gamma function (bug #30088)
David Bateman <dbateman@free.fr>
parents:
10155
diff
changeset
|
229 %!assert (gammainc(single(0:4),single(0.5),"upper"), single(1)-gammainc(single(0:4),single(0.5)),single(1e-7)) |
fa00ccf7b1f9
Implementary complementary incomplete gamma function (bug #30088)
David Bateman <dbateman@free.fr>
parents:
10155
diff
changeset
|
230 |
7815
a41df65f3f00
Add some single precision test code and fix resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
231 */ |