]> git.ipfire.org Git - thirdparty/gcc.git/blame - libgfortran/m4/bessel.m4
Update copyright years.
[thirdparty/gcc.git] / libgfortran / m4 / bessel.m4
CommitLineData
faa9fea4 1`/* Implementation of the BESSEL_JN and BESSEL_YN transformational
2 function using a recurrence algorithm.
fbd26352 3 Copyright (C) 2010-2019 Free Software Foundation, Inc.
faa9fea4 4 Contributed by Tobias Burnus <burnus@net-b.de>
5
6This file is part of the GNU Fortran runtime library (libgfortran).
7
8Libgfortran is free software; you can redistribute it and/or
9modify it under the terms of the GNU General Public
10License as published by the Free Software Foundation; either
11version 3 of the License, or (at your option) any later version.
12
13Libgfortran is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16GNU General Public License for more details.
17
18Under Section 7 of GPL version 3, you are granted additional
19permissions described in the GCC Runtime Library Exception, version
203.1, as published by the Free Software Foundation.
21
22You should have received a copy of the GNU General Public License and
23a copy of the GCC Runtime Library Exception along with this program;
24see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
25<http://www.gnu.org/licenses/>. */
26
1eb99442 27#include "libgfortran.h"'
faa9fea4 28
29include(iparm.m4)dnl
30include(`mtype.m4')dnl
31
9dc59fdf 32mathfunc_macro
33
faa9fea4 34`#if defined (HAVE_'rtype_name`)
35
36
37
9dc59fdf 38#if 'hasmathfunc(jn)`
faa9fea4 39extern void bessel_jn_r'rtype_kind` ('rtype` * const restrict ret, int n1,
40 int n2, 'rtype_name` x);
41export_proto(bessel_jn_r'rtype_kind`);
42
43void
44bessel_jn_r'rtype_kind` ('rtype` * const restrict ret, int n1, int n2, 'rtype_name` x)
45{
46 int i;
47 index_type stride;
48
49 'rtype_name` last1, last2, x2rev;
50
51 stride = GFC_DESCRIPTOR_STRIDE(ret,0);
52
553877d9 53 if (ret->base_addr == NULL)
faa9fea4 54 {
55 size_t size = n2 < n1 ? 0 : n2-n1+1;
56 GFC_DIMENSION_SET(ret->dim[0], 0, size-1, 1);
af1e9051 57 ret->base_addr = xmallocarray (size, sizeof ('rtype_name`));
faa9fea4 58 ret->offset = 0;
59 }
60
61 if (unlikely (n2 < n1))
62 return;
63
64 if (unlikely (compile_options.bounds_check)
65 && GFC_DESCRIPTOR_EXTENT(ret,0) != (n2-n1+1))
66 runtime_error("Incorrect extent in return value of BESSEL_JN "
67 "(%ld vs. %ld)", (long int) n2-n1,
96138327 68 (long int) GFC_DESCRIPTOR_EXTENT(ret,0));
faa9fea4 69
70 stride = GFC_DESCRIPTOR_STRIDE(ret,0);
71
9dc59fdf 72 if (unlikely (x == 0))
faa9fea4 73 {
553877d9 74 ret->base_addr[0] = 1;
faa9fea4 75 for (i = 1; i <= n2-n1; i++)
553877d9 76 ret->base_addr[i*stride] = 0;
faa9fea4 77 return;
78 }
79
9dc59fdf 80 last1 = MATHFUNC(jn) (n2, x);
553877d9 81 ret->base_addr[(n2-n1)*stride] = last1;
faa9fea4 82
83 if (n1 == n2)
84 return;
85
9dc59fdf 86 last2 = MATHFUNC(jn) (n2 - 1, x);
553877d9 87 ret->base_addr[(n2-n1-1)*stride] = last2;
faa9fea4 88
89 if (n1 + 1 == n2)
90 return;
91
9dc59fdf 92 x2rev = GFC_REAL_'rtype_kind`_LITERAL(2.)/x;
faa9fea4 93
94 for (i = n2-n1-2; i >= 0; i--)
95 {
553877d9 96 ret->base_addr[i*stride] = x2rev * (i+1+n1) * last2 - last1;
faa9fea4 97 last1 = last2;
553877d9 98 last2 = ret->base_addr[i*stride];
faa9fea4 99 }
100}
101
102#endif
103
9dc59fdf 104#if 'hasmathfunc(yn)`
faa9fea4 105extern void bessel_yn_r'rtype_kind` ('rtype` * const restrict ret,
106 int n1, int n2, 'rtype_name` x);
107export_proto(bessel_yn_r'rtype_kind`);
108
109void
110bessel_yn_r'rtype_kind` ('rtype` * const restrict ret, int n1, int n2,
111 'rtype_name` x)
112{
113 int i;
114 index_type stride;
115
116 'rtype_name` last1, last2, x2rev;
117
118 stride = GFC_DESCRIPTOR_STRIDE(ret,0);
119
553877d9 120 if (ret->base_addr == NULL)
faa9fea4 121 {
122 size_t size = n2 < n1 ? 0 : n2-n1+1;
123 GFC_DIMENSION_SET(ret->dim[0], 0, size-1, 1);
af1e9051 124 ret->base_addr = xmallocarray (size, sizeof ('rtype_name`));
faa9fea4 125 ret->offset = 0;
126 }
127
128 if (unlikely (n2 < n1))
129 return;
130
131 if (unlikely (compile_options.bounds_check)
132 && GFC_DESCRIPTOR_EXTENT(ret,0) != (n2-n1+1))
133 runtime_error("Incorrect extent in return value of BESSEL_JN "
134 "(%ld vs. %ld)", (long int) n2-n1,
96138327 135 (long int) GFC_DESCRIPTOR_EXTENT(ret,0));
faa9fea4 136
137 stride = GFC_DESCRIPTOR_STRIDE(ret,0);
138
9dc59fdf 139 if (unlikely (x == 0))
faa9fea4 140 {
141 for (i = 0; i <= n2-n1; i++)
142#if defined('rtype_name`_INFINITY)
553877d9 143 ret->base_addr[i*stride] = -'rtype_name`_INFINITY;
faa9fea4 144#else
553877d9 145 ret->base_addr[i*stride] = -'rtype_name`_HUGE;
faa9fea4 146#endif
147 return;
148 }
149
9dc59fdf 150 last1 = MATHFUNC(yn) (n1, x);
553877d9 151 ret->base_addr[0] = last1;
faa9fea4 152
153 if (n1 == n2)
154 return;
155
9dc59fdf 156 last2 = MATHFUNC(yn) (n1 + 1, x);
553877d9 157 ret->base_addr[1*stride] = last2;
faa9fea4 158
159 if (n1 + 1 == n2)
160 return;
161
9dc59fdf 162 x2rev = GFC_REAL_'rtype_kind`_LITERAL(2.)/x;
faa9fea4 163
9872e76f 164 for (i = 2; i <= n2 - n1; i++)
faa9fea4 165 {
166#if defined('rtype_name`_INFINITY)
167 if (unlikely (last2 == -'rtype_name`_INFINITY))
168 {
553877d9 169 ret->base_addr[i*stride] = -'rtype_name`_INFINITY;
faa9fea4 170 }
171 else
172#endif
173 {
553877d9 174 ret->base_addr[i*stride] = x2rev * (i-1+n1) * last2 - last1;
faa9fea4 175 last1 = last2;
553877d9 176 last2 = ret->base_addr[i*stride];
faa9fea4 177 }
178 }
179}
180#endif
181
182#endif'
183