Mercurial > octave
annotate scripts/specfun/cosint.m @ 30564:796f54d4ddbf stable
update Octave Project Developers copyright for the new year
In files that have the "Octave Project Developers" copyright notice,
update for 2021.
In all .txi and .texi files except gpl.txi and gpl.texi in the
doc/liboctave and doc/interpreter directories, change the copyright
to "Octave Project Developers", the same as used for other source
files. Update copyright notices for 2022 (not done since 2019). For
gpl.txi and gpl.texi, change the copyright notice to be "Free Software
Foundation, Inc." and leave the date at 2007 only because this file
only contains the text of the GPL, not anything created by the Octave
Project Developers.
Add Paul Thomas to contributors.in.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 28 Dec 2021 18:22:40 -0500 |
parents | 01de0045b2e3 |
children | 5d3faba0342e |
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 ## |
30564
796f54d4ddbf
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
30330
diff
changeset
|
3 ## Copyright (C) 2017-2022 The Octave Project Developers |
27918
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
27800
diff
changeset
|
4 ## |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 ## See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 ## distribution or <https://octave.org/copyright/>. |
24909
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
7 ## |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
8 ## This file is part of Octave. |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
9 ## |
24927
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
24923
diff
changeset
|
10 ## Octave is free software: you can redistribute it and/or modify it |
24909
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
11 ## under the terms of the GNU General Public License as published by |
24927
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
24923
diff
changeset
|
12 ## the Free Software Foundation, either version 3 of the License, or |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
24923
diff
changeset
|
13 ## (at your option) any later version. |
24909
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
14 ## |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
15 ## Octave is distributed in the hope that it will be useful, but |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
24927
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
24923
diff
changeset
|
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
24923
diff
changeset
|
18 ## GNU General Public License for more details. |
24909
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
19 ## |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
20 ## You should have received a copy of the GNU General Public License |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
21 ## along with Octave; see the file COPYING. If not, see |
24927
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
24923
diff
changeset
|
22 ## <https://www.gnu.org/licenses/>. |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 ## |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 ######################################################################## |
24909
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
25 |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
26 ## -*- texinfo -*- |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
27 ## @deftypefn {} {} cosint (@var{x}) |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
28 ## Compute the cosine integral function: |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
29 ## @tex |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
30 ## $$ |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
31 ## {\rm Ci} (x) = - \int_x^\infty {{\cos (t)} \over t} dt |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
32 ## $$ |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
33 ## @end tex |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
34 ## @ifnottex |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
35 ## |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
36 ## @example |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
37 ## @group |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
38 ## +oo |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
39 ## / |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
40 ## Ci (x) = - | (cos (t)) / t dt |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
41 ## / |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
42 ## x |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
43 ## @end group |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
44 ## @end example |
24927
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
24923
diff
changeset
|
45 ## |
24909
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
46 ## @end ifnottex |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
47 ## An equivalent definition is |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
48 ## @tex |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
49 ## $$ |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
50 ## {\rm Ci} (x) = \gamma + \log (x) + \int_0^x {{\cos (t) - 1} \over t} dt |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
51 ## $$ |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
52 ## @end tex |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
53 ## @ifnottex |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
54 ## |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
55 ## @example |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
56 ## @group |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
57 ## x |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
58 ## / |
24927
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
24923
diff
changeset
|
59 ## | cos (t) - 1 |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
24923
diff
changeset
|
60 ## Ci (x) = gamma + log (x) + | ------------- dt |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
24923
diff
changeset
|
61 ## | t |
24909
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
62 ## / |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
63 ## 0 |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
64 ## @end group |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
65 ## @end example |
24927
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
24923
diff
changeset
|
66 ## |
24909
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
67 ## @end ifnottex |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
68 ## Reference: |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
69 ## |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
70 ## @nospell{M. Abramowitz and I.A. Stegun}, |
27800
5a6a19a4e3da
doc: Use Texinfo non-sentence ending periods in citations.
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
71 ## @cite{Handbook of Mathematical Functions}, 1964. |
24909
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
72 ## |
24927
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
24923
diff
changeset
|
73 ## @seealso{sinint, expint, cos} |
24909
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
74 ## |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
75 ## @end deftypefn |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
76 |
24927
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
24923
diff
changeset
|
77 function y = cosint (x) |
24909
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
78 |
28891
de5f2f9a64ff
maint: Use same coding style when checking for a minimum of 1 input.
Rik <rik@octave.org>
parents:
28886
diff
changeset
|
79 if (nargin < 1) |
24909
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
80 print_usage (); |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
81 endif |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
82 |
24927
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
24923
diff
changeset
|
83 if (! isnumeric (x)) |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
24923
diff
changeset
|
84 error ("cosint: X must be numeric"); |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
24923
diff
changeset
|
85 endif |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
24923
diff
changeset
|
86 |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
24923
diff
changeset
|
87 ## Convert to floating point if necessary |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
24923
diff
changeset
|
88 if (isinteger (x)) |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
24923
diff
changeset
|
89 x = double (x); |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
24923
diff
changeset
|
90 endif |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
24923
diff
changeset
|
91 |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
24923
diff
changeset
|
92 ## Convert to column vector |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
24923
diff
changeset
|
93 orig_sz = size (x); |
24913
9da779d2f029
cosint improve signed zero imag input near branch cut
Colin Macdonald <cbm@m.fsf.org>
parents:
24911
diff
changeset
|
94 if (iscomplex (x)) |
24927
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
24923
diff
changeset
|
95 ## Work around reshape which narrows to real (bug #52953) |
24913
9da779d2f029
cosint improve signed zero imag input near branch cut
Colin Macdonald <cbm@m.fsf.org>
parents:
24911
diff
changeset
|
96 x = complex (real (x)(:), imag (x)(:)); |
9da779d2f029
cosint improve signed zero imag input near branch cut
Colin Macdonald <cbm@m.fsf.org>
parents:
24911
diff
changeset
|
97 else |
9da779d2f029
cosint improve signed zero imag input near branch cut
Colin Macdonald <cbm@m.fsf.org>
parents:
24911
diff
changeset
|
98 x = x(:); |
28947
b73a54c31152
maint: Use Octave-specific end keywords rather than just 'end'.
Rik <rik@octave.org>
parents:
28923
diff
changeset
|
99 endif |
24913
9da779d2f029
cosint improve signed zero imag input near branch cut
Colin Macdonald <cbm@m.fsf.org>
parents:
24911
diff
changeset
|
100 |
24927
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
24923
diff
changeset
|
101 ## Initialize the result |
24911
8d6f3941a118
Support single precision in sinint/cosint.
Colin Macdonald <cbm@m.fsf.org>
parents:
24910
diff
changeset
|
102 y = zeros (size (x), class (x)); |
8d6f3941a118
Support single precision in sinint/cosint.
Colin Macdonald <cbm@m.fsf.org>
parents:
24910
diff
changeset
|
103 tol = eps (class (x)); |
24909
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
104 |
24927
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
24923
diff
changeset
|
105 todo = true (size (x)); |
24909
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
106 |
24927
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
24923
diff
changeset
|
107 ## Special values |
24909
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
108 y(x == Inf) = 0; |
28923
3f8e1fa0eed2
maint: Use space after '!' logical not operator.
Rik <rik@octave.org>
parents:
28912
diff
changeset
|
109 y((x == -Inf) & ! signbit (imag (x))) = 1i * pi; |
24927
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
24923
diff
changeset
|
110 y((x == -Inf) & signbit (imag (x))) = -1i * pi; |
24909
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
111 |
24927
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
24923
diff
changeset
|
112 todo(isinf (x)) = false; |
24909
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
113 |
24927
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
24923
diff
changeset
|
114 ## For values large in modulus, but not in the range (-oo,0), we use the |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
24923
diff
changeset
|
115 ## relation with expint. |
24909
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
116 |
24915
c6cdacb1794e
cosint: solved problem with big negative real values.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
24914
diff
changeset
|
117 flag_large = (abs (x) > 2); |
24909
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
118 xx = x(flag_large); |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
119 |
24910
b98755ef7572
Style changes in sinint/cosint.
Colin Macdonald <cbm@m.fsf.org>
parents:
24909
diff
changeset
|
120 ## Abramowitz, relation 5.2.20 |
24915
c6cdacb1794e
cosint: solved problem with big negative real values.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
24914
diff
changeset
|
121 ii_sw = (real (xx) <= 0 & imag (xx) < 0); |
24909
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
122 xx(ii_sw) = conj (xx(ii_sw)); |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
123 ii_nw = (real (xx) < 0); |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
124 xx(ii_nw) *= -1; |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
125 yy = -0.5 * (expint (1i * xx) + expint (-1i * xx)); |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
126 yy(ii_nw) += 1i * pi; |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
127 yy(ii_sw) = conj (yy(ii_sw)); |
24927
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
24923
diff
changeset
|
128 y(todo & flag_large) = yy; |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
24923
diff
changeset
|
129 |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
24923
diff
changeset
|
130 todo(flag_large) = false; |
24909
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
131 |
24910
b98755ef7572
Style changes in sinint/cosint.
Colin Macdonald <cbm@m.fsf.org>
parents:
24909
diff
changeset
|
132 ## For values small in modulus, use the series expansion (also near (-oo, 0]) |
24913
9da779d2f029
cosint improve signed zero imag input near branch cut
Colin Macdonald <cbm@m.fsf.org>
parents:
24911
diff
changeset
|
133 if (iscomplex (x)) |
9da779d2f029
cosint improve signed zero imag input near branch cut
Colin Macdonald <cbm@m.fsf.org>
parents:
24911
diff
changeset
|
134 ## indexing can lose imag part: if it was -0, we could end up on the |
9da779d2f029
cosint improve signed zero imag input near branch cut
Colin Macdonald <cbm@m.fsf.org>
parents:
24911
diff
changeset
|
135 ## wrong right side of the branch cut along the negative real axis. |
24927
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
24923
diff
changeset
|
136 xx = complex (real (x)(todo), imag (x)(todo)); |
24913
9da779d2f029
cosint improve signed zero imag input near branch cut
Colin Macdonald <cbm@m.fsf.org>
parents:
24911
diff
changeset
|
137 else |
24927
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
24923
diff
changeset
|
138 xx = x(todo); |
28947
b73a54c31152
maint: Use Octave-specific end keywords rather than just 'end'.
Rik <rik@octave.org>
parents:
28923
diff
changeset
|
139 endif |
24909
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
140 ssum = - xx .^ 2 / 4; # First term of the series expansion |
24927
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
24923
diff
changeset
|
141 ## FIXME: This is way more precision than a double value can hold. |
24909
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
142 gma = 0.57721566490153286060651209008; # Euler gamma constant |
30330
01de0045b2e3
maint: Shorten some long lines to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents:
30254
diff
changeset
|
143 yy = gma + log (complex (xx)) + ssum; # log (complex (Z)) handles signed zero |
24927
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
24923
diff
changeset
|
144 flag_sum = true (nnz (todo), 1); |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
24923
diff
changeset
|
145 it = 0; |
24909
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
146 maxit = 300; |
26268
6dd232798997
maint: Remove useless ';' from end of for, if, while, etc. statements.
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
147 while (any (flag_sum) && (++it < maxit)) |
24909
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
148 ssum .*= - xx .^ 2 * (2 * it) / ((2 * it + 2) ^ 2 * (2 * it + 1)); |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
149 yy(flag_sum) += ssum (flag_sum); |
24911
8d6f3941a118
Support single precision in sinint/cosint.
Colin Macdonald <cbm@m.fsf.org>
parents:
24910
diff
changeset
|
150 flag_sum = (abs (ssum) >= tol); |
24909
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
151 endwhile |
24927
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
24923
diff
changeset
|
152 y(todo) = yy; |
24909
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
153 |
24927
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
24923
diff
changeset
|
154 ## Clean up values which are purely real |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
24923
diff
changeset
|
155 flag_neg_zero_imag = (real (x) < 0) & (imag (x) == 0) & signbit (imag (x)); |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
24923
diff
changeset
|
156 y(flag_neg_zero_imag) = complex (real (y(flag_neg_zero_imag)), -pi); |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
24923
diff
changeset
|
157 |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
24923
diff
changeset
|
158 ## Restore original shape |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
24923
diff
changeset
|
159 y = reshape (y, orig_sz); |
24909
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
160 |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
161 endfunction |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
162 |
24910
b98755ef7572
Style changes in sinint/cosint.
Colin Macdonald <cbm@m.fsf.org>
parents:
24909
diff
changeset
|
163 |
28907
11f1207111c5
maint: Don't use semicolon at end of single-line BIST tests.
Rik <rik@octave.org>
parents:
28891
diff
changeset
|
164 %!assert (cosint (1.1), 0.38487337742465081550, 2 * eps) |
24909
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
165 |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
166 %!test |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
167 %! x = [2, 3, pi; exp(1), 5, 6]; |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
168 %! A = cosint (x); |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
169 %! B = [0.422980828774864996, 0.119629786008000328, 0.0736679120464254860; ... |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
170 %! 0.213958001340379779, -0.190029749656643879, -0.0680572438932471262]; |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
171 %! assert (A, B, -5e-15); |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
172 |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
173 %!assert (cosint (0), - Inf) |
24913
9da779d2f029
cosint improve signed zero imag input near branch cut
Colin Macdonald <cbm@m.fsf.org>
parents:
24911
diff
changeset
|
174 %!assert (cosint (-0), -inf + 1i*pi) |
9da779d2f029
cosint improve signed zero imag input near branch cut
Colin Macdonald <cbm@m.fsf.org>
parents:
24911
diff
changeset
|
175 %!assert (cosint (complex (-0, 0)), -inf + 1i*pi) |
9da779d2f029
cosint improve signed zero imag input near branch cut
Colin Macdonald <cbm@m.fsf.org>
parents:
24911
diff
changeset
|
176 %!assert (cosint (complex (-0, -0)), -inf - 1i*pi) |
24909
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
177 %!assert (cosint (inf), 0) |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
178 %!assert (cosint (-inf), 1i * pi) |
24913
9da779d2f029
cosint improve signed zero imag input near branch cut
Colin Macdonald <cbm@m.fsf.org>
parents:
24911
diff
changeset
|
179 %!assert (cosint (complex (-inf, -0)), -1i * pi) |
24911
8d6f3941a118
Support single precision in sinint/cosint.
Colin Macdonald <cbm@m.fsf.org>
parents:
24910
diff
changeset
|
180 %!assert (isnan (cosint (nan))) |
8d6f3941a118
Support single precision in sinint/cosint.
Colin Macdonald <cbm@m.fsf.org>
parents:
24910
diff
changeset
|
181 |
8d6f3941a118
Support single precision in sinint/cosint.
Colin Macdonald <cbm@m.fsf.org>
parents:
24910
diff
changeset
|
182 %!assert (class (cosint (single (1))), "single") |
24909
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
183 |
24927
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
24923
diff
changeset
|
184 ## tests against maple |
24909
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
185 %!assert (cosint (1), 0.337403922900968135, -2*eps) |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
186 %!assert (cosint (-1), 0.337403922900968135 + 3.14159265358979324*I, -2*eps) |
30254
0fc950301a50
cosint.m: Increase tolerance in BIST (bug #61358).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29793
diff
changeset
|
187 %!assert (cosint (pi), 0.0736679120464254860, -4e-15) |
24909
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
188 %!assert (cosint (-pi), 0.0736679120464254860 + 3.14159265358979324*I, -2*eps) |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
189 %!assert (cosint (300), -0.00333219991859211178, -2*eps) |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
190 %!assert (cosint (1e4), -0.0000305519167244852127, -2*eps) |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
191 %!assert (cosint (20i), 1.28078263320282944e7 + 1.57079632679489662*I, -2*eps) |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
192 |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
193 %!test |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
194 %! x = (0:4).'; |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
195 %! y_ex = [-Inf |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
196 %! 0.337403922900968135 |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
197 %! 0.422980828774864996 |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
198 %! 0.119629786008000328 |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
199 %! -0.140981697886930412]; |
24927
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
24923
diff
changeset
|
200 %! assert (cosint (x), y_ex, -3e-15); |
24909
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
201 |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
202 %!test |
24913
9da779d2f029
cosint improve signed zero imag input near branch cut
Colin Macdonald <cbm@m.fsf.org>
parents:
24911
diff
changeset
|
203 %! x = -(1:4).'; |
9da779d2f029
cosint improve signed zero imag input near branch cut
Colin Macdonald <cbm@m.fsf.org>
parents:
24911
diff
changeset
|
204 %! y_ex = [0.337403922900968135 + pi*1i |
9da779d2f029
cosint improve signed zero imag input near branch cut
Colin Macdonald <cbm@m.fsf.org>
parents:
24911
diff
changeset
|
205 %! 0.422980828774864996 + pi*1i |
9da779d2f029
cosint improve signed zero imag input near branch cut
Colin Macdonald <cbm@m.fsf.org>
parents:
24911
diff
changeset
|
206 %! 0.119629786008000328 + pi*1i |
9da779d2f029
cosint improve signed zero imag input near branch cut
Colin Macdonald <cbm@m.fsf.org>
parents:
24911
diff
changeset
|
207 %! -0.140981697886930412 + pi*1i]; |
9da779d2f029
cosint improve signed zero imag input near branch cut
Colin Macdonald <cbm@m.fsf.org>
parents:
24911
diff
changeset
|
208 %! assert (cosint (x), y_ex, -4*eps); |
9da779d2f029
cosint improve signed zero imag input near branch cut
Colin Macdonald <cbm@m.fsf.org>
parents:
24911
diff
changeset
|
209 |
24916
bddd9ecfa420
Cosint: solved problem with -0i
Michele Ginesi <michele.ginesi@gmail.com>
parents:
24915
diff
changeset
|
210 %!test |
24927
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
24923
diff
changeset
|
211 %! x = complex (-(1:4).', 0); |
24916
bddd9ecfa420
Cosint: solved problem with -0i
Michele Ginesi <michele.ginesi@gmail.com>
parents:
24915
diff
changeset
|
212 %! y_ex = [0.337403922900968135 + pi*1i |
bddd9ecfa420
Cosint: solved problem with -0i
Michele Ginesi <michele.ginesi@gmail.com>
parents:
24915
diff
changeset
|
213 %! 0.422980828774864996 + pi*1i |
bddd9ecfa420
Cosint: solved problem with -0i
Michele Ginesi <michele.ginesi@gmail.com>
parents:
24915
diff
changeset
|
214 %! 0.119629786008000328 + pi*1i |
bddd9ecfa420
Cosint: solved problem with -0i
Michele Ginesi <michele.ginesi@gmail.com>
parents:
24915
diff
changeset
|
215 %! -0.140981697886930412 + pi*1i]; |
bddd9ecfa420
Cosint: solved problem with -0i
Michele Ginesi <michele.ginesi@gmail.com>
parents:
24915
diff
changeset
|
216 %! assert (cosint (x), y_ex, -4*eps); |
bddd9ecfa420
Cosint: solved problem with -0i
Michele Ginesi <michele.ginesi@gmail.com>
parents:
24915
diff
changeset
|
217 |
bddd9ecfa420
Cosint: solved problem with -0i
Michele Ginesi <michele.ginesi@gmail.com>
parents:
24915
diff
changeset
|
218 %!test |
24913
9da779d2f029
cosint improve signed zero imag input near branch cut
Colin Macdonald <cbm@m.fsf.org>
parents:
24911
diff
changeset
|
219 %! x = complex (-(1:4).', -0); |
9da779d2f029
cosint improve signed zero imag input near branch cut
Colin Macdonald <cbm@m.fsf.org>
parents:
24911
diff
changeset
|
220 %! y_ex = [0.337403922900968135 - pi*1i |
9da779d2f029
cosint improve signed zero imag input near branch cut
Colin Macdonald <cbm@m.fsf.org>
parents:
24911
diff
changeset
|
221 %! 0.422980828774864996 - pi*1i |
9da779d2f029
cosint improve signed zero imag input near branch cut
Colin Macdonald <cbm@m.fsf.org>
parents:
24911
diff
changeset
|
222 %! 0.119629786008000328 - pi*1i |
9da779d2f029
cosint improve signed zero imag input near branch cut
Colin Macdonald <cbm@m.fsf.org>
parents:
24911
diff
changeset
|
223 %! -0.140981697886930412 - pi*1i]; |
24909
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
224 %! assert (cosint (x), y_ex, -4*eps); |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
225 |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
226 %!test |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
227 %! x = 1i * (0:4).'; |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
228 %! y_ex = [-Inf |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
229 %! 0.837866940980208241 + 1.57079632679489662*I |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
230 %! 2.45266692264691452 + 1.57079632679489662*I |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
231 %! 4.96039209476560976 + 1.57079632679489662*I |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
232 %! 9.81354755882318556 + 1.57079632679489662*I]; |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
233 %! assert (cosint (x), y_ex, -4*eps); |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
234 |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
235 %!test |
24913
9da779d2f029
cosint improve signed zero imag input near branch cut
Colin Macdonald <cbm@m.fsf.org>
parents:
24911
diff
changeset
|
236 %! x = -1i * (1:4).'; |
9da779d2f029
cosint improve signed zero imag input near branch cut
Colin Macdonald <cbm@m.fsf.org>
parents:
24911
diff
changeset
|
237 %! y_ex = [0.837866940980208241 - 1.57079632679489662*I |
24909
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
238 %! 2.45266692264691452 - 1.57079632679489662*I |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
239 %! 4.96039209476560976 - 1.57079632679489662*I |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
240 %! 9.81354755882318556 - 1.57079632679489662*I]; |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
241 %! assert (cosint (x), y_ex, -4*eps); |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
242 |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
243 %!test |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
244 %! x = [1+2i; -2+5i; 2-5i; 100; 10i; -1e-4 + 1e-6*1i; -20-1i]; |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
245 %! A = [ 2.03029639329172164 - 0.151907155175856884*I |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
246 %! 1.61538963829107749 + 19.7257540553382650*I |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
247 %! 1.61538963829107749 + 16.5841614017484717*I |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
248 %! -0.00514882514261049214 |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
249 %! 1246.11448604245441 + 1.57079632679489662*I |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
250 %! -8.63307471207423322 + 3.13159298695312800*I |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
251 %! 0.0698222284673061493 - 3.11847446254772946*I ]; |
4a341330ee15
Added sine integral and cosine integral functions.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
diff
changeset
|
252 %! B = cosint (x); |
24927
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
24923
diff
changeset
|
253 %! assert (A, B, -3*eps); |
24911
8d6f3941a118
Support single precision in sinint/cosint.
Colin Macdonald <cbm@m.fsf.org>
parents:
24910
diff
changeset
|
254 %! B = cosint (single (x)); |
24927
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
24923
diff
changeset
|
255 %! assert (A, B, -3*eps ("single")); |
24914
d7293106945c
cosint fails for large x along negative real axis.
Colin Macdonald <cbm@m.fsf.org>
parents:
24913
diff
changeset
|
256 |
24927
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
24923
diff
changeset
|
257 ## Fails along negative real axis |
24915
c6cdacb1794e
cosint: solved problem with big negative real values.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
24914
diff
changeset
|
258 %!test |
c6cdacb1794e
cosint: solved problem with big negative real values.
Michele Ginesi <michele.ginesi@gmail.com>
parents:
24914
diff
changeset
|
259 %! x = [-25; -100; -1000]; |
24914
d7293106945c
cosint fails for large x along negative real axis.
Colin Macdonald <cbm@m.fsf.org>
parents:
24913
diff
changeset
|
260 %! yex = [-0.0068485971797025909189 + pi*1i |
d7293106945c
cosint fails for large x along negative real axis.
Colin Macdonald <cbm@m.fsf.org>
parents:
24913
diff
changeset
|
261 %! -0.0051488251426104921444 + pi*1i |
d7293106945c
cosint fails for large x along negative real axis.
Colin Macdonald <cbm@m.fsf.org>
parents:
24913
diff
changeset
|
262 %! 0.000826315511090682282 + pi*1i]; |
d7293106945c
cosint fails for large x along negative real axis.
Colin Macdonald <cbm@m.fsf.org>
parents:
24913
diff
changeset
|
263 %! y = cosint (x); |
24927
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
24923
diff
changeset
|
264 %! assert (y, yex, -5*eps); |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
24923
diff
changeset
|
265 |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
24923
diff
changeset
|
266 ## FIXME: Need a test for bug #52953 |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
24923
diff
changeset
|
267 %#!test <*52953> |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
24923
diff
changeset
|
268 |
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
24923
diff
changeset
|
269 ## Test input validation |
28886
d8318c12d903
test: remove unnecessary BIST tests in m-files checking for excessive number of inputs.
Rik <rik@octave.org>
parents:
27978
diff
changeset
|
270 %!error <Invalid call> cosint () |
24927
c280560d9c96
Overhaul special functions modified by GSOC2018 project.
Rik <rik@octave.org>
parents:
24923
diff
changeset
|
271 %!error <X must be numeric> cosint ("1") |