OSDN Git Service

mn10300: Delete ASM_PN_FORMAT.
[pf3gnuchains/gcc-fork.git] / libgfortran / generated / bessel_r16.c
1 /* Implementation of the BESSEL_JN and BESSEL_YN transformational
2    function using a recurrence algorithm.
3    Copyright 2010 Free Software Foundation, Inc.
4    Contributed by Tobias Burnus <burnus@net-b.de>
5
6 This file is part of the GNU Fortran runtime library (libgfortran).
7
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.
12
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.
17
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.
21
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/>.  */
26
27 #include "libgfortran.h"
28 #include <stdlib.h>
29 #include <assert.h>
30
31
32
33 #if defined(GFC_REAL_16_IS_FLOAT128)
34 #define MATHFUNC(funcname) funcname ## q
35 #else
36 #define MATHFUNC(funcname) funcname ## l
37 #endif
38 #if defined(GFC_REAL_16_IS_FLOAT128)
39 #define BUILTINMATHFUNC(funcname) funcname ## q
40 #else
41 #define BUILTINMATHFUNC(funcname) funcname ## l
42 #endif
43
44 #if defined (HAVE_GFC_REAL_16)
45
46
47
48 #if (defined(GFC_REAL_16_IS_FLOAT128) || defined(HAVE_JNL))
49 extern void bessel_jn_r16 (gfc_array_r16 * const restrict ret, int n1,
50                                      int n2, GFC_REAL_16 x);
51 export_proto(bessel_jn_r16);
52
53 void
54 bessel_jn_r16 (gfc_array_r16 * const restrict ret, int n1, int n2, GFC_REAL_16 x)
55 {
56   int i;
57   index_type stride;
58
59   GFC_REAL_16 last1, last2, x2rev;
60
61   stride = GFC_DESCRIPTOR_STRIDE(ret,0);
62
63   if (ret->data == NULL)
64     {
65       size_t size = n2 < n1 ? 0 : n2-n1+1; 
66       GFC_DIMENSION_SET(ret->dim[0], 0, size-1, 1);
67       ret->data = internal_malloc_size (sizeof (GFC_REAL_16) * size);
68       ret->offset = 0;
69     }
70
71   if (unlikely (n2 < n1))
72     return;
73
74   if (unlikely (compile_options.bounds_check)
75       && GFC_DESCRIPTOR_EXTENT(ret,0) != (n2-n1+1))
76     runtime_error("Incorrect extent in return value of BESSEL_JN "
77                   "(%ld vs. %ld)", (long int) n2-n1,
78                   (long int) GFC_DESCRIPTOR_EXTENT(ret,0));
79
80   stride = GFC_DESCRIPTOR_STRIDE(ret,0);
81
82   if (unlikely (x == 0))
83     {
84       ret->data[0] = 1;
85       for (i = 1; i <= n2-n1; i++)
86         ret->data[i*stride] = 0;
87       return;
88     }
89
90   ret->data = ret->data;
91   last1 = MATHFUNC(jn) (n2, x);
92   ret->data[(n2-n1)*stride] = last1;
93
94   if (n1 == n2)
95     return;
96
97   last2 = MATHFUNC(jn) (n2 - 1, x);
98   ret->data[(n2-n1-1)*stride] = last2;
99
100   if (n1 + 1 == n2)
101     return;
102
103   x2rev = GFC_REAL_16_LITERAL(2.)/x;
104
105   for (i = n2-n1-2; i >= 0; i--)
106     {
107       ret->data[i*stride] = x2rev * (i+1+n1) * last2 - last1;
108       last1 = last2;
109       last2 = ret->data[i*stride];
110     }
111 }
112
113 #endif
114
115 #if (defined(GFC_REAL_16_IS_FLOAT128) || defined(HAVE_YNL))
116 extern void bessel_yn_r16 (gfc_array_r16 * const restrict ret,
117                                      int n1, int n2, GFC_REAL_16 x);
118 export_proto(bessel_yn_r16);
119
120 void
121 bessel_yn_r16 (gfc_array_r16 * const restrict ret, int n1, int n2,
122                          GFC_REAL_16 x)
123 {
124   int i;
125   index_type stride;
126
127   GFC_REAL_16 last1, last2, x2rev;
128
129   stride = GFC_DESCRIPTOR_STRIDE(ret,0);
130
131   if (ret->data == NULL)
132     {
133       size_t size = n2 < n1 ? 0 : n2-n1+1; 
134       GFC_DIMENSION_SET(ret->dim[0], 0, size-1, 1);
135       ret->data = internal_malloc_size (sizeof (GFC_REAL_16) * size);
136       ret->offset = 0;
137     }
138
139   if (unlikely (n2 < n1))
140     return;
141
142   if (unlikely (compile_options.bounds_check)
143       && GFC_DESCRIPTOR_EXTENT(ret,0) != (n2-n1+1))
144     runtime_error("Incorrect extent in return value of BESSEL_JN "
145                   "(%ld vs. %ld)", (long int) n2-n1,
146                   (long int) GFC_DESCRIPTOR_EXTENT(ret,0));
147
148   stride = GFC_DESCRIPTOR_STRIDE(ret,0);
149
150   if (unlikely (x == 0))
151     {
152       for (i = 0; i <= n2-n1; i++)
153 #if defined(GFC_REAL_16_INFINITY)
154         ret->data[i*stride] = -GFC_REAL_16_INFINITY;
155 #else
156         ret->data[i*stride] = -GFC_REAL_16_HUGE;
157 #endif
158       return;
159     }
160
161   ret->data = ret->data;
162   last1 = MATHFUNC(yn) (n1, x);
163   ret->data[0] = last1;
164
165   if (n1 == n2)
166     return;
167
168   last2 = MATHFUNC(yn) (n1 + 1, x);
169   ret->data[1*stride] = last2;
170
171   if (n1 + 1 == n2)
172     return;
173
174   x2rev = GFC_REAL_16_LITERAL(2.)/x;
175
176   for (i = 2; i <= n1+n2; i++)
177     {
178 #if defined(GFC_REAL_16_INFINITY)
179       if (unlikely (last2 == -GFC_REAL_16_INFINITY))
180         {
181           ret->data[i*stride] = -GFC_REAL_16_INFINITY;
182         }
183       else
184 #endif
185         {
186           ret->data[i*stride] = x2rev * (i-1+n1) * last2 - last1;
187           last1 = last2;
188           last2 = ret->data[i*stride];
189         }
190     }
191 }
192 #endif
193
194 #endif
195