OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libgfortran/] [generated/] [bessel_r10.c] - Blame information for rev 733

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.