Mercurial > octave
annotate libinterp/corefcn/__expint__.cc @ 29958:32c3a5805893
move DEFUN and DEFMETHOD functions inside octave namespace
* mk-opts.pl: Surround emitted function definitions with
OCTAVE_NAMESPACE_BEGIN and OCTAVE_NAMESPACE_END tags.
* mk-builtins.pl: Surround emitted function declarations with
OCTAVE_NAMESPACE_BEGIN and OCTAVE_NAMESPACE_END tags. Emit deprecated
global inline functions.
* __betainc__.cc, __contourc__.cc, __dsearchn__.cc, __eigs__.cc,
__expint__.cc, __ftp__.cc, __gammainc__.cc, __ichol__.cc, __ilu__.cc,
__lin_interpn__.cc, __magick_read__.cc, __pchip_deriv__.cc, __qp__.cc,
amd.cc, balance.cc, besselj.cc, bitfcns.cc, bsxfun.cc, call-stack.cc,
ccolamd.cc, cellfun.cc, chol.cc, colamd.cc, colloc.cc, conv2.cc,
daspk.cc, dasrt.cc, dassl.cc, data.cc, debug.cc, defaults.cc,
defun.cc, det.cc, dirfns.cc, display.cc, dlmread.cc, dmperm.cc,
dot.cc, eig.cc, ellipj.cc, environment.cc, error.cc, event-manager.cc,
fcn-info.cc, fft.cc, fft2.cc, fftn.cc, file-io.cc, filter.cc, find.cc,
gcd.cc, getgrent.cc, getpwent.cc, getrusage.cc, givens.cc,
graphics.cc, gsvd.cc, hash.cc, help.cc, hess.cc, hex2num.cc, input.cc,
interpreter.cc, inv.cc, jsondecode.cc, jsonencode.cc, kron.cc,
load-path.cc, load-save.cc, lookup.cc, ls-oct-text.cc, lsode.cc,
lu.cc, mappers.cc, matrix_type.cc, max.cc, mgorth.cc, nproc.cc,
oct-hist.cc, ordqz.cc, ordschur.cc, pager.cc, pinv.cc, pr-flt-fmt.cc,
pr-output.cc, psi.cc, qr.cc, quad.cc, quadcc.cc, qz.cc, rand.cc,
rcond.cc, regexp.cc, schur.cc, settings.cc, sighandlers.cc, sparse.cc,
spparms.cc, sqrtm.cc, stream-euler.cc, strfind.cc, strfns.cc,
sub2ind.cc, svd.cc, sylvester.cc, symbfact.cc, symrcm.cc, symtab.cc,
syscalls.cc, sysdep.cc, time.cc, toplev.cc, tril.cc, tsearch.cc,
typecast.cc, urlwrite.cc, utils.cc, variables.cc, __delaunayn__.cc,
__fltk_uigetfile__.cc, __glpk__.cc, __init_gnuplot__.cc, __ode15__.cc,
__voronoi__.cc, audiodevinfo.cc, audioread.cc, convhulln.cc, fftw.cc,
gzip.cc, ov-base.cc, ov-bool-mat.cc, ov-cell.cc, ov-class.cc,
ov-classdef.cc, ov-fcn-handle.cc, ov-java.cc, ov-null-mat.cc,
ov-oncleanup.cc, ov-struct.cc, ov-typeinfo.cc, ov-usr-fcn.cc, ov.cc,
octave.cc, lex.ll, oct-parse.yy, profiler.cc, pt-eval.cc: Surround
DEFUN and DEFMETHOD function defnitions with OCTAVE_NAMESPACE_BEGIN
and OCTAVE_NAMESPACE_END tags.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 13 Aug 2021 21:53:51 -0400 |
parents | 7854d5752dd2 |
children | 7d6709900da7 |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 //////////////////////////////////////////////////////////////////////// |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 // |
29358
0a5b15007766
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
3 // Copyright (C) 2018-2021 The Octave Project Developers |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
4 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 // See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 // distribution or <https://octave.org/copyright/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
7 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
8 // This file is part of Octave. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
9 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
10 // Octave is free software: you can redistribute it and/or modify it |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
11 // under the terms of the GNU General Public License as published by |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
12 // the Free Software Foundation, either version 3 of the License, or |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
13 // (at your option) any later version. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
14 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
15 // Octave is distributed in the hope that it will be useful, but |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
16 // WITHOUT ANY WARRANTY; without even the implied warranty of |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
18 // GNU General Public License for more details. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
19 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
20 // You should have received a copy of the GNU General Public License |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
21 // along with Octave; see the file COPYING. If not, see |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
22 // <https://www.gnu.org/licenses/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 //////////////////////////////////////////////////////////////////////// |
24927
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
25 |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
26 #if defined (HAVE_CONFIG_H) |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
27 # include "config.h" |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
28 #endif |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
29 |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
30 #include "CNDArray.h" |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
31 #include "defun.h" |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
32 #include "fCNDArray.h" |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
33 |
29958
32c3a5805893
move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
34 OCTAVE_NAMESPACE_BEGIN |
32c3a5805893
move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
35 |
24927
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
36 DEFUN (__expint__, args, , |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
37 doc: /* -*- texinfo -*- |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
38 @deftypefn {} {@var{y} =} __expint__ (@var{x}) |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
39 Continued fraction expansion for the exponential integral. |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
40 @end deftypefn */) |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
41 { |
28946
ef2b0a00daef
maint: Don't declare nargin in C++ files if it is used only once.
Rik <rik@octave.org>
parents:
27923
diff
changeset
|
42 if (args.length () != 1) |
24927
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
43 print_usage (); |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
44 |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
45 octave_value_list retval; |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
46 |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
47 bool is_single = args(0).is_single_type (); |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
48 |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
49 int numel_x = args(0).numel (); |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
50 |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
51 // Initialize output dimension vector |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
52 dim_vector output_dv (numel_x, 1); |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
53 |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
54 // Lentz's algorithm in two cases: single and double precision |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
55 if (is_single) |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
56 { |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
57 // Initialize output and inputs |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
58 FloatComplexColumnVector output (output_dv); |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
59 FloatComplexNDArray x; |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
60 |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
61 if (numel_x == 1) |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
62 x = FloatComplexNDArray (output_dv, args(0).float_complex_value ()); |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
63 else |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
64 x = args(0).float_complex_array_value (); |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
65 |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
66 // Initialize variables used in algorithm |
25542
e5208e98ab92
fix ambiguous overload build error on Solaris (bug #54217)
Mike Miller <mtmiller@octave.org>
parents:
25059
diff
changeset
|
67 static const FloatComplex tiny = octave::math::exp2 (-50.0f); |
24927
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
68 static const float eps = std::numeric_limits<float>::epsilon (); |
25052
576ff914979c
__expint__.cc: Fix heap-buffer-overflow (bug #53514).
Rik <rik@octave.org>
parents:
24927
diff
changeset
|
69 const FloatComplex cone (1.0, 0.0); |
576ff914979c
__expint__.cc: Fix heap-buffer-overflow (bug #53514).
Rik <rik@octave.org>
parents:
24927
diff
changeset
|
70 const FloatComplex czero (0.0, 0.0); |
576ff914979c
__expint__.cc: Fix heap-buffer-overflow (bug #53514).
Rik <rik@octave.org>
parents:
24927
diff
changeset
|
71 const int maxit = 100; |
24927
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
72 |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
73 // Loop over all elements |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
74 for (octave_idx_type i = 0; i < numel_x; ++i) |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
75 { |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
76 // Catch Ctrl+C |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
77 OCTAVE_QUIT; |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
78 |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
79 // Variable initialization for the current element |
25052
576ff914979c
__expint__.cc: Fix heap-buffer-overflow (bug #53514).
Rik <rik@octave.org>
parents:
24927
diff
changeset
|
80 FloatComplex xj = x(i); |
576ff914979c
__expint__.cc: Fix heap-buffer-overflow (bug #53514).
Rik <rik@octave.org>
parents:
24927
diff
changeset
|
81 FloatComplex y = tiny; |
576ff914979c
__expint__.cc: Fix heap-buffer-overflow (bug #53514).
Rik <rik@octave.org>
parents:
24927
diff
changeset
|
82 FloatComplex Cj = y; |
576ff914979c
__expint__.cc: Fix heap-buffer-overflow (bug #53514).
Rik <rik@octave.org>
parents:
24927
diff
changeset
|
83 FloatComplex Dj = czero; |
576ff914979c
__expint__.cc: Fix heap-buffer-overflow (bug #53514).
Rik <rik@octave.org>
parents:
24927
diff
changeset
|
84 FloatComplex alpha_j = cone; |
576ff914979c
__expint__.cc: Fix heap-buffer-overflow (bug #53514).
Rik <rik@octave.org>
parents:
24927
diff
changeset
|
85 FloatComplex beta_j = xj; |
576ff914979c
__expint__.cc: Fix heap-buffer-overflow (bug #53514).
Rik <rik@octave.org>
parents:
24927
diff
changeset
|
86 FloatComplex Deltaj = czero; |
576ff914979c
__expint__.cc: Fix heap-buffer-overflow (bug #53514).
Rik <rik@octave.org>
parents:
24927
diff
changeset
|
87 int j = 1; |
24927
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
88 |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
89 // Lentz's algorithm |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
90 while ((std::abs (Deltaj - cone) > eps) && (j < maxit)) |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
91 { |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
92 Dj = beta_j + alpha_j * Dj; |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
93 if (Dj == czero) |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
94 Dj = tiny; |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
95 Cj = beta_j + alpha_j / Cj; |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
96 if (Cj == czero) |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
97 Cj = tiny; |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
98 Dj = cone / Dj; |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
99 Deltaj = Cj * Dj; |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
100 y *= Deltaj; |
25542
e5208e98ab92
fix ambiguous overload build error on Solaris (bug #54217)
Mike Miller <mtmiller@octave.org>
parents:
25059
diff
changeset
|
101 alpha_j = (j + 1) / 2; |
24927
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
102 if ((j % 2) == 0) |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
103 beta_j = xj; |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
104 else |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
105 beta_j = cone; |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
106 j++; |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
107 } |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
108 |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
109 output(i) = y; |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
110 } |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
111 retval(0) = output; |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
112 } |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
113 else |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
114 { |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
115 // Initialize output and inputs |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
116 ComplexColumnVector output (output_dv); |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
117 ComplexNDArray x; |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
118 |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
119 if (numel_x == 1) |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
120 x = ComplexNDArray (output_dv, args(0).complex_value ()); |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
121 else |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
122 x = args(0).complex_array_value (); |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
123 |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
124 // Initialize variables used in algorithm |
25542
e5208e98ab92
fix ambiguous overload build error on Solaris (bug #54217)
Mike Miller <mtmiller@octave.org>
parents:
25059
diff
changeset
|
125 static const Complex tiny = octave::math::exp2 (-100.0); |
24927
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
126 static const double eps = std::numeric_limits<double>::epsilon (); |
25052
576ff914979c
__expint__.cc: Fix heap-buffer-overflow (bug #53514).
Rik <rik@octave.org>
parents:
24927
diff
changeset
|
127 const Complex cone (1.0, 0.0); |
576ff914979c
__expint__.cc: Fix heap-buffer-overflow (bug #53514).
Rik <rik@octave.org>
parents:
24927
diff
changeset
|
128 const Complex czero (0.0, 0.0); |
576ff914979c
__expint__.cc: Fix heap-buffer-overflow (bug #53514).
Rik <rik@octave.org>
parents:
24927
diff
changeset
|
129 const int maxit = 200; |
24927
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
130 |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
131 // Loop over all scenarios |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
132 for (octave_idx_type i = 0; i < numel_x; ++i) |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
133 { |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
134 // Catch Ctrl+C |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
135 OCTAVE_QUIT; |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
136 |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
137 // Variable initialization for the current element |
25052
576ff914979c
__expint__.cc: Fix heap-buffer-overflow (bug #53514).
Rik <rik@octave.org>
parents:
24927
diff
changeset
|
138 Complex xj = x(i); |
576ff914979c
__expint__.cc: Fix heap-buffer-overflow (bug #53514).
Rik <rik@octave.org>
parents:
24927
diff
changeset
|
139 Complex y = tiny; |
576ff914979c
__expint__.cc: Fix heap-buffer-overflow (bug #53514).
Rik <rik@octave.org>
parents:
24927
diff
changeset
|
140 Complex Cj = y; |
576ff914979c
__expint__.cc: Fix heap-buffer-overflow (bug #53514).
Rik <rik@octave.org>
parents:
24927
diff
changeset
|
141 Complex Dj = czero; |
576ff914979c
__expint__.cc: Fix heap-buffer-overflow (bug #53514).
Rik <rik@octave.org>
parents:
24927
diff
changeset
|
142 Complex alpha_j = cone; |
576ff914979c
__expint__.cc: Fix heap-buffer-overflow (bug #53514).
Rik <rik@octave.org>
parents:
24927
diff
changeset
|
143 Complex beta_j = xj; |
576ff914979c
__expint__.cc: Fix heap-buffer-overflow (bug #53514).
Rik <rik@octave.org>
parents:
24927
diff
changeset
|
144 Complex Deltaj = czero; |
576ff914979c
__expint__.cc: Fix heap-buffer-overflow (bug #53514).
Rik <rik@octave.org>
parents:
24927
diff
changeset
|
145 int j = 1; |
24927
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
146 |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
147 // Lentz's algorithm |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
148 while ((std::abs (Deltaj - cone) > eps) && (j < maxit)) |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
149 { |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
150 Dj = beta_j + alpha_j * Dj; |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
151 if (Dj == czero) |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
152 Dj = tiny; |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
153 Cj = beta_j + alpha_j / Cj; |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
154 if (Cj == czero) |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
155 Cj = tiny; |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
156 Dj = cone / Dj; |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
157 Deltaj = Cj * Dj; |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
158 y *= Deltaj; |
25542
e5208e98ab92
fix ambiguous overload build error on Solaris (bug #54217)
Mike Miller <mtmiller@octave.org>
parents:
25059
diff
changeset
|
159 alpha_j = (j + 1) / 2; |
24927
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
160 if ((j % 2) == 0) |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
161 beta_j = xj; |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
162 else |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
163 beta_j = cone; |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
164 j++; |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
165 } |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
166 |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
167 output(i) = y; |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
168 } |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
169 |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
170 retval(0) = output; |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
171 } |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
172 |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
173 return retval; |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
diff
changeset
|
174 } |
29958
32c3a5805893
move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
175 |
32c3a5805893
move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
176 OCTAVE_NAMESPACE_END |