OSDN Git Service

Remove duplicate ".endfunc".
[pf3gnuchains/gcc-fork.git] / libgfortran / generated / bessel_r10.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 #define MATHFUNC(funcname) funcname ## l
34 #define BUILTINMATHFUNC(funcname) MATHFUNC(funcname)
35
36 #if defined (HAVE_GFC_REAL_10)
37
38
39
40 #if defined (HAVE_JNL)
41 extern void bessel_jn_r10 (gfc_array_r10 * const restrict ret, int n1,
42                                      int n2, GFC_REAL_10 x);
43 export_proto(bessel_jn_r10);
44
45 void
46 bessel_jn_r10 (gfc_array_r10 * const restrict ret, int n1, int n2, GFC_REAL_10 x)
47 {
48   int i;
49   index_type stride;
50
51   GFC_REAL_10 last1, last2, x2rev;
52
53   stride = GFC_DESCRIPTOR_STRIDE(ret,0);
54
55   if (ret->data == NULL)
56     {
57       size_t size = n2 < n1 ? 0 : n2-n1+1; 
58       GFC_DIMENSION_SET(ret->dim[0], 0, size-1, 1);
59       ret->data = internal_malloc_size (sizeof (GFC_REAL_10) * size);
60       ret->offset = 0;
61     }
62
63   if (unlikely (n2 < n1))
64     return;
65
66   if (unlikely (compile_options.bounds_check)
67       && GFC_DESCRIPTOR_EXTENT(ret,0) != (n2-n1+1))
68     runtime_error("Incorrect extent in return value of BESSEL_JN "
69                   "(%ld vs. %ld)", (long int) n2-n1,
70                   (long int) GFC_DESCRIPTOR_EXTENT(ret,0));
71
72   stride = GFC_DESCRIPTOR_STRIDE(ret,0);
73
74   if (unlikely (x == 0))
75     {
76       ret->data[0] = 1;
77       for (i = 1; i <= n2-n1; i++)
78         ret->data[i*stride] = 0;
79       return;
80     }
81
82   ret->data = ret->data;
83   last1 = MATHFUNC(jn) (n2, x);
84   ret->data[(n2-n1)*stride] = last1;
85
86   if (n1 == n2)
87     return;
88
89   last2 = MATHFUNC(jn) (n2 - 1, x);
90   ret->data[(n2-n1-1)*stride] = last2;
91
92   if (n1 + 1 == n2)
93     return;
94
95   x2rev = GFC_REAL_10_LITERAL(2.)/x;
96
97   for (i = n2-n1-2; i >= 0; i--)
98     {
99       ret->data[i*stride] = x2rev * (i+1+n1) * last2 - last1;
100       last1 = last2;
101       last2 = ret->data[i*stride];
102     }
103 }
104
105 #endif
106
107 #if defined (HAVE_YNL)
108 extern void bessel_yn_r10 (gfc_array_r10 * const restrict ret,
109                                      int n1, int n2, GFC_REAL_10 x);
110 export_proto(bessel_yn_r10);
111
112 void
113 bessel_yn_r10 (gfc_array_r10 * const restrict ret, int n1, int n2,
114                          GFC_REAL_10 x)
115 {
116   int i;
117   index_type stride;
118
119   GFC_REAL_10 last1, last2, x2rev;
120
121   stride = GFC_DESCRIPTOR_STRIDE(ret,0);
122
123   if (ret->data == NULL)
124     {
125       size_t size = n2 < n1 ? 0 : n2-n1+1; 
126       GFC_DIMENSION_SET(ret->dim[0], 0, size-1, 1);
127       ret->data = internal_malloc_size (sizeof (GFC_REAL_10) * size);
128       ret->offset = 0;
129     }
130
131   if (unlikely (n2 < n1))
132     return;
133
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));
139
140   stride = GFC_DESCRIPTOR_STRIDE(ret,0);
141
142   if (unlikely (x == 0))
143     {
144       for (i = 0; i <= n2-n1; i++)
145 #if defined(GFC_REAL_10_INFINITY)
146         ret->data[i*stride] = -GFC_REAL_10_INFINITY;
147 #else
148         ret->data[i*stride] = -GFC_REAL_10_HUGE;
149 #endif
150       return;
151     }
152
153   ret->data = ret->data;
154   last1 = MATHFUNC(yn) (n1, x);
155   ret->data[0] = last1;
156
157   if (n1 == n2)
158     return;
159
160   last2 = MATHFUNC(yn) (n1 + 1, x);
161   ret->data[1*stride] = last2;
162
163   if (n1 + 1 == n2)
164     return;
165
166   x2rev = GFC_REAL_10_LITERAL(2.)/x;
167
168   for (i = 2; i <= n1+n2; i++)
169     {
170 #if defined(GFC_REAL_10_INFINITY)
171       if (unlikely (last2 == -GFC_REAL_10_INFINITY))
172         {
173           ret->data[i*stride] = -GFC_REAL_10_INFINITY;
174         }
175       else
176 #endif
177         {
178           ret->data[i*stride] = x2rev * (i-1+n1) * last2 - last1;
179           last1 = last2;
180           last2 = ret->data[i*stride];
181         }
182     }
183 }
184 #endif
185
186 #endif
187