]> gcc.gnu.org Git - gcc.git/blame - libgfortran/generated/bessel_r4.c
Update copyright years.
[gcc.git] / libgfortran / generated / bessel_r4.c
CommitLineData
47b99694
TB
1/* Implementation of the BESSEL_JN and BESSEL_YN transformational
2 function using a recurrence algorithm.
5624e564 3 Copyright (C) 2010-2015 Free Software Foundation, Inc.
47b99694
TB
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
27#include "libgfortran.h"
28#include <stdlib.h>
29#include <assert.h>
30
31
08fd13d4
FXC
32
33#define MATHFUNC(funcname) funcname ## f
34
47b99694
TB
35#if defined (HAVE_GFC_REAL_4)
36
37
38
39#if defined (HAVE_JNF)
40extern void bessel_jn_r4 (gfc_array_r4 * const restrict ret, int n1,
41 int n2, GFC_REAL_4 x);
42export_proto(bessel_jn_r4);
43
44void
45bessel_jn_r4 (gfc_array_r4 * const restrict ret, int n1, int n2, GFC_REAL_4 x)
46{
47 int i;
48 index_type stride;
49
50 GFC_REAL_4 last1, last2, x2rev;
51
52 stride = GFC_DESCRIPTOR_STRIDE(ret,0);
53
21d1335b 54 if (ret->base_addr == NULL)
47b99694
TB
55 {
56 size_t size = n2 < n1 ? 0 : n2-n1+1;
57 GFC_DIMENSION_SET(ret->dim[0], 0, size-1, 1);
92e6f3a4 58 ret->base_addr = xmallocarray (size, sizeof (GFC_REAL_4));
47b99694
TB
59 ret->offset = 0;
60 }
61
62 if (unlikely (n2 < n1))
63 return;
64
65 if (unlikely (compile_options.bounds_check)
66 && GFC_DESCRIPTOR_EXTENT(ret,0) != (n2-n1+1))
67 runtime_error("Incorrect extent in return value of BESSEL_JN "
68 "(%ld vs. %ld)", (long int) n2-n1,
28cc1e9a 69 (long int) GFC_DESCRIPTOR_EXTENT(ret,0));
47b99694
TB
70
71 stride = GFC_DESCRIPTOR_STRIDE(ret,0);
72
08fd13d4 73 if (unlikely (x == 0))
47b99694 74 {
21d1335b 75 ret->base_addr[0] = 1;
47b99694 76 for (i = 1; i <= n2-n1; i++)
21d1335b 77 ret->base_addr[i*stride] = 0;
47b99694
TB
78 return;
79 }
80
08fd13d4 81 last1 = MATHFUNC(jn) (n2, x);
21d1335b 82 ret->base_addr[(n2-n1)*stride] = last1;
47b99694
TB
83
84 if (n1 == n2)
85 return;
86
08fd13d4 87 last2 = MATHFUNC(jn) (n2 - 1, x);
21d1335b 88 ret->base_addr[(n2-n1-1)*stride] = last2;
47b99694
TB
89
90 if (n1 + 1 == n2)
91 return;
92
08fd13d4 93 x2rev = GFC_REAL_4_LITERAL(2.)/x;
47b99694
TB
94
95 for (i = n2-n1-2; i >= 0; i--)
96 {
21d1335b 97 ret->base_addr[i*stride] = x2rev * (i+1+n1) * last2 - last1;
47b99694 98 last1 = last2;
21d1335b 99 last2 = ret->base_addr[i*stride];
47b99694
TB
100 }
101}
102
103#endif
104
105#if defined (HAVE_YNF)
106extern void bessel_yn_r4 (gfc_array_r4 * const restrict ret,
107 int n1, int n2, GFC_REAL_4 x);
108export_proto(bessel_yn_r4);
109
110void
111bessel_yn_r4 (gfc_array_r4 * const restrict ret, int n1, int n2,
112 GFC_REAL_4 x)
113{
114 int i;
115 index_type stride;
116
117 GFC_REAL_4 last1, last2, x2rev;
118
119 stride = GFC_DESCRIPTOR_STRIDE(ret,0);
120
21d1335b 121 if (ret->base_addr == NULL)
47b99694
TB
122 {
123 size_t size = n2 < n1 ? 0 : n2-n1+1;
124 GFC_DIMENSION_SET(ret->dim[0], 0, size-1, 1);
92e6f3a4 125 ret->base_addr = xmallocarray (size, sizeof (GFC_REAL_4));
47b99694
TB
126 ret->offset = 0;
127 }
128
129 if (unlikely (n2 < n1))
130 return;
131
132 if (unlikely (compile_options.bounds_check)
133 && GFC_DESCRIPTOR_EXTENT(ret,0) != (n2-n1+1))
134 runtime_error("Incorrect extent in return value of BESSEL_JN "
135 "(%ld vs. %ld)", (long int) n2-n1,
28cc1e9a 136 (long int) GFC_DESCRIPTOR_EXTENT(ret,0));
47b99694
TB
137
138 stride = GFC_DESCRIPTOR_STRIDE(ret,0);
139
08fd13d4 140 if (unlikely (x == 0))
47b99694
TB
141 {
142 for (i = 0; i <= n2-n1; i++)
143#if defined(GFC_REAL_4_INFINITY)
21d1335b 144 ret->base_addr[i*stride] = -GFC_REAL_4_INFINITY;
47b99694 145#else
21d1335b 146 ret->base_addr[i*stride] = -GFC_REAL_4_HUGE;
47b99694
TB
147#endif
148 return;
149 }
150
08fd13d4 151 last1 = MATHFUNC(yn) (n1, x);
21d1335b 152 ret->base_addr[0] = last1;
47b99694
TB
153
154 if (n1 == n2)
155 return;
156
08fd13d4 157 last2 = MATHFUNC(yn) (n1 + 1, x);
21d1335b 158 ret->base_addr[1*stride] = last2;
47b99694
TB
159
160 if (n1 + 1 == n2)
161 return;
162
08fd13d4 163 x2rev = GFC_REAL_4_LITERAL(2.)/x;
47b99694 164
0d43a91d 165 for (i = 2; i <= n2 - n1; i++)
47b99694
TB
166 {
167#if defined(GFC_REAL_4_INFINITY)
168 if (unlikely (last2 == -GFC_REAL_4_INFINITY))
169 {
21d1335b 170 ret->base_addr[i*stride] = -GFC_REAL_4_INFINITY;
47b99694
TB
171 }
172 else
173#endif
174 {
21d1335b 175 ret->base_addr[i*stride] = x2rev * (i-1+n1) * last2 - last1;
47b99694 176 last1 = last2;
21d1335b 177 last2 = ret->base_addr[i*stride];
47b99694
TB
178 }
179 }
180}
181#endif
182
183#endif
184
This page took 0.451264 seconds and 5 git commands to generate.