Fix hash-table violation in trans-decl.c.
[official-gcc.git] / libgfortran / generated / bessel_r16.c
blob59d456137e6dbb4bec939e11afdd337ec5552232
1 /* Implementation of the BESSEL_JN and BESSEL_YN transformational
2 function using a recurrence algorithm.
3 Copyright (C) 2010-2018 Free Software Foundation, Inc.
4 Contributed by Tobias Burnus <burnus@net-b.de>
6 This file is part of the GNU Fortran runtime library (libgfortran).
8 Libgfortran is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public
10 License as published by the Free Software Foundation; either
11 version 3 of the License, or (at your option) any later version.
13 Libgfortran is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 Under Section 7 of GPL version 3, you are granted additional
19 permissions described in the GCC Runtime Library Exception, version
20 3.1, as published by the Free Software Foundation.
22 You should have received a copy of the GNU General Public License and
23 a copy of the GCC Runtime Library Exception along with this program;
24 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
25 <http://www.gnu.org/licenses/>. */
27 #include "libgfortran.h"
31 #if defined(GFC_REAL_16_IS_FLOAT128)
32 #define MATHFUNC(funcname) funcname ## q
33 #else
34 #define MATHFUNC(funcname) funcname ## l
35 #endif
37 #if defined (HAVE_GFC_REAL_16)
41 #if (defined(GFC_REAL_16_IS_FLOAT128) || defined(HAVE_JNL))
42 extern void bessel_jn_r16 (gfc_array_r16 * const restrict ret, int n1,
43 int n2, GFC_REAL_16 x);
44 export_proto(bessel_jn_r16);
46 void
47 bessel_jn_r16 (gfc_array_r16 * const restrict ret, int n1, int n2, GFC_REAL_16 x)
49 int i;
50 index_type stride;
52 GFC_REAL_16 last1, last2, x2rev;
54 stride = GFC_DESCRIPTOR_STRIDE(ret,0);
56 if (ret->base_addr == NULL)
58 size_t size = n2 < n1 ? 0 : n2-n1+1;
59 GFC_DIMENSION_SET(ret->dim[0], 0, size-1, 1);
60 ret->base_addr = xmallocarray (size, sizeof (GFC_REAL_16));
61 ret->offset = 0;
64 if (unlikely (n2 < n1))
65 return;
67 if (unlikely (compile_options.bounds_check)
68 && GFC_DESCRIPTOR_EXTENT(ret,0) != (n2-n1+1))
69 runtime_error("Incorrect extent in return value of BESSEL_JN "
70 "(%ld vs. %ld)", (long int) n2-n1,
71 (long int) GFC_DESCRIPTOR_EXTENT(ret,0));
73 stride = GFC_DESCRIPTOR_STRIDE(ret,0);
75 if (unlikely (x == 0))
77 ret->base_addr[0] = 1;
78 for (i = 1; i <= n2-n1; i++)
79 ret->base_addr[i*stride] = 0;
80 return;
83 last1 = MATHFUNC(jn) (n2, x);
84 ret->base_addr[(n2-n1)*stride] = last1;
86 if (n1 == n2)
87 return;
89 last2 = MATHFUNC(jn) (n2 - 1, x);
90 ret->base_addr[(n2-n1-1)*stride] = last2;
92 if (n1 + 1 == n2)
93 return;
95 x2rev = GFC_REAL_16_LITERAL(2.)/x;
97 for (i = n2-n1-2; i >= 0; i--)
99 ret->base_addr[i*stride] = x2rev * (i+1+n1) * last2 - last1;
100 last1 = last2;
101 last2 = ret->base_addr[i*stride];
105 #endif
107 #if (defined(GFC_REAL_16_IS_FLOAT128) || defined(HAVE_YNL))
108 extern void bessel_yn_r16 (gfc_array_r16 * const restrict ret,
109 int n1, int n2, GFC_REAL_16 x);
110 export_proto(bessel_yn_r16);
112 void
113 bessel_yn_r16 (gfc_array_r16 * const restrict ret, int n1, int n2,
114 GFC_REAL_16 x)
116 int i;
117 index_type stride;
119 GFC_REAL_16 last1, last2, x2rev;
121 stride = GFC_DESCRIPTOR_STRIDE(ret,0);
123 if (ret->base_addr == NULL)
125 size_t size = n2 < n1 ? 0 : n2-n1+1;
126 GFC_DIMENSION_SET(ret->dim[0], 0, size-1, 1);
127 ret->base_addr = xmallocarray (size, sizeof (GFC_REAL_16));
128 ret->offset = 0;
131 if (unlikely (n2 < n1))
132 return;
134 if (unlikely (compile_options.bounds_check)
135 && GFC_DESCRIPTOR_EXTENT(ret,0) != (n2-n1+1))
136 runtime_error("Incorrect extent in return value of BESSEL_JN "
137 "(%ld vs. %ld)", (long int) n2-n1,
138 (long int) GFC_DESCRIPTOR_EXTENT(ret,0));
140 stride = GFC_DESCRIPTOR_STRIDE(ret,0);
142 if (unlikely (x == 0))
144 for (i = 0; i <= n2-n1; i++)
145 #if defined(GFC_REAL_16_INFINITY)
146 ret->base_addr[i*stride] = -GFC_REAL_16_INFINITY;
147 #else
148 ret->base_addr[i*stride] = -GFC_REAL_16_HUGE;
149 #endif
150 return;
153 last1 = MATHFUNC(yn) (n1, x);
154 ret->base_addr[0] = last1;
156 if (n1 == n2)
157 return;
159 last2 = MATHFUNC(yn) (n1 + 1, x);
160 ret->base_addr[1*stride] = last2;
162 if (n1 + 1 == n2)
163 return;
165 x2rev = GFC_REAL_16_LITERAL(2.)/x;
167 for (i = 2; i <= n2 - n1; i++)
169 #if defined(GFC_REAL_16_INFINITY)
170 if (unlikely (last2 == -GFC_REAL_16_INFINITY))
172 ret->base_addr[i*stride] = -GFC_REAL_16_INFINITY;
174 else
175 #endif
177 ret->base_addr[i*stride] = x2rev * (i-1+n1) * last2 - last1;
178 last1 = last2;
179 last2 = ret->base_addr[i*stride];
183 #endif
185 #endif