10
10
# Polynomial coefficients are from [1] which is based on [2].
11
11
# For tiny arugments the power series expansion is used.
12
12
#
13
- # Branch 2: 5.0 < x < 75 .0
13
+ # Branch 2: 5.0 < x < 25 .0
14
14
# bessely0 = sqrt(2/(pi*x))*(sin(x - pi/4)*R7(x) - cos(x - pi/4)*R8(x))
15
15
# Hankel's asymptotic expansion is used
16
16
# where R7 and R8 are rational functions (Pn(x)/Qn(x)) of degree 7 and 8 respectively
17
17
# See section 4 of [3] for more details and [1] for coefficients of polynomials
18
18
#
19
- # Branch 3: x >= 75 .0
19
+ # Branch 3: x >= 25 .0
20
20
# bessely0 = sqrt(2/(pi*x))*beta(x)*(sin(x - pi/4 - alpha(x))
21
21
# See modified expansions given in [3]. Exact coefficients are used.
22
22
#
28
28
# [3] Harrison, John. "Fast and accurate Bessel function computation."
29
29
# 2009 19th IEEE Symposium on Computer Arithmetic. IEEE, 2009.
30
30
#
31
+
32
+ """
33
+ bessely0(x::T) where T <: Union{Float32, Float64}
34
+
35
+ Bessel function of the second kind of order zero, ``Y_0(x)``.
36
+ """
31
37
function bessely0 (x:: T ) where T <: Union{Float32, Float64}
32
38
if x <= zero (x)
33
39
if iszero (x)
@@ -42,29 +48,33 @@ function bessely0(x::T) where T <: Union{Float32, Float64}
42
48
end
43
49
function _bessely0_compute (x:: Float64 )
44
50
T = Float64
45
- if x <= 5
51
+ if x <= 5.0
46
52
z = x * x
47
53
w = evalpoly (z, YP_y0 (T)) / evalpoly (z, YQ_y0 (T))
48
54
w += TWOOPI (T) * log (x) * besselj0 (x)
49
55
return w
50
- elseif x < 75 .0
51
- w = T ( 5 ) / x
52
- z = w* w
56
+ elseif x < 25 .0
57
+ w = 5.0 / x
58
+ z = w * w
53
59
p = evalpoly (z, PP_y0 (T)) / evalpoly (z, PQ_y0 (T))
54
60
q = evalpoly (z, QP_y0 (T)) / evalpoly (z, QQ_y0 (T))
55
61
xn = x - PIO4 (T)
56
62
sc = sincos (xn)
57
63
p = p * sc[1 ] + w * q * sc[2 ]
58
64
return p * SQ2OPI (T) / sqrt (x)
59
65
else
66
+ if x < 120.0
67
+ p = (one (T), - 1 / 16 , 53 / 512 , - 4447 / 8192 , 3066403 / 524288 , - 896631415 / 8388608 , 796754802993 / 268435456 , - 500528959023471 / 4294967296 )
68
+ q = (- 1 / 8 , 25 / 384 , - 1073 / 5120 , 375733 / 229376 , - 55384775 / 2359296 , 24713030909 / 46137344 , - 7780757249041 / 436207616 )
69
+ else
70
+ p = (one (T), - 1 / 16 , 53 / 512 , - 4447 / 8192 )
71
+ q = (- 1 / 8 , 25 / 384 , - 1073 / 5120 , 375733 / 229376 )
72
+ end
60
73
xinv = inv (x)
61
74
x2 = xinv* xinv
62
75
63
- p = (one (T), - 1 / 16 , 53 / 512 , - 4447 / 8192 , 5066403 / 524288 )
64
76
p = evalpoly (x2, p)
65
77
a = SQ2OPI (T) * sqrt (xinv) * p
66
-
67
- q = (- 1 / 8 , 25 / 384 , - 1073 / 5120 , 375733 / 229376 , - 55384775 / 2359296 )
68
78
xn = muladd (xinv, evalpoly (x2, q), - PIO4 (T))
69
79
70
80
# the following computes b = sin(x + xn) more accurately
@@ -91,6 +101,12 @@ function _bessely0_compute(x::Float32)
91
101
return p
92
102
end
93
103
end
104
+
105
+ """
106
+ bessely1(x::T) where T <: Union{Float32, Float64}
107
+
108
+ Bessel function of the second kind of order one, ``Y_1(x)``.
109
+ """
94
110
function bessely1 (x:: T ) where T <: Union{Float32, Float64}
95
111
if x <= zero (x)
96
112
if iszero (x)
@@ -103,16 +119,15 @@ function bessely1(x::T) where T <: Union{Float32, Float64}
103
119
end
104
120
return _bessely1_compute (x)
105
121
end
106
-
107
122
function _bessely1_compute (x:: Float64 )
108
123
T = Float64
109
124
if x <= 5
110
125
z = x * x
111
126
w = x * (evalpoly (z, YP_y1 (T)) / evalpoly (z, YQ_y1 (T)))
112
127
w += TWOOPI (T) * (besselj1 (x) * log (x) - inv (x))
113
128
return w
114
- elseif x < 75 .0
115
- w = T ( 5 ) / x
129
+ elseif x < 25 .0
130
+ w = 5.0 / x
116
131
z = w * w
117
132
p = evalpoly (z, PP_j1 (T)) / evalpoly (z, PQ_j1 (T))
118
133
q = evalpoly (z, QP_j1 (T)) / evalpoly (z, QQ_j1 (T))
@@ -121,14 +136,18 @@ function _bessely1_compute(x::Float64)
121
136
p = p * sc[1 ] + w * q * sc[2 ]
122
137
return p * SQ2OPI (T) / sqrt (x)
123
138
else
139
+ if x < 120.0
140
+ p = (one (T), 3 / 16 , - 99 / 512 , 6597 / 8192 , - 4057965 / 524288 , 1113686901 / 8388608 , - 951148335159 / 268435456 , 581513783771781 / 4294967296 )
141
+ q = (3 / 8 , - 21 / 128 , 1899 / 5120 , - 543483 / 229376 , 8027901 / 262144 , - 30413055339 / 46137344 , 9228545313147 / 436207616 )
142
+ else
143
+ p = (one (T), 3 / 16 , - 99 / 512 , 6597 / 8192 )
144
+ q = (3 / 8 , - 21 / 128 , 1899 / 5120 , - 543483 / 229376 )
145
+ end
124
146
xinv = inv (x)
125
147
x2 = xinv* xinv
126
148
127
- p = (one (T), 3 / 16 , - 99 / 512 , 6597 / 8192 , - 4057965 / 524288 )
128
149
p = evalpoly (x2, p)
129
150
a = SQ2OPI (T) * sqrt (xinv) * p
130
-
131
- q = (3 / 8 , - 21 / 128 , 1899 / 5120 , - 543483 / 229376 , 8027901 / 262144 )
132
151
xn = muladd (xinv, evalpoly (x2, q), - 3 * PIO4 (T))
133
152
134
153
# the following computes b = sin(x + xn) more accurately
@@ -137,7 +156,6 @@ function _bessely1_compute(x::Float64)
137
156
return a * b
138
157
end
139
158
end
140
-
141
159
function _bessely1_compute (x:: Float32 )
142
160
T = Float32
143
161
if x <= 2.0f0
0 commit comments