Skip to content

Commit 3d2f133

Browse files
committed
j1, y1 float32
1 parent a7c57d7 commit 3d2f133

File tree

4 files changed

+82
-0
lines changed

4 files changed

+82
-0
lines changed

src/constants.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ const TWOOPI(::Type{Float64}) = 0.6366197723675814
99

1010
const PIO4(::Type{Float32}) = 0.78539816339744830962f0
1111
const TWOOPI(::Type{Float32}) = 0.636619772367581343075535f0
12+
const THPIO4(::Type{Float32}) = 2.35619449019234492885f0

src/j1.jl

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1+
function besselj1(x::Float32)
2+
if x < zero(x)
3+
x = -x
4+
end
5+
if x <= 2.0f0
6+
z = x * x
7+
Z1 = 1.46819706421238932572f1
8+
p = (z - Z1) * x * evalpoly(z, JP32)
9+
return p
10+
else
11+
q = inv(x)
12+
w = sqrt(q)
13+
p = w * evalpoly(q, MO132)
14+
w = q * q
15+
xn = q * evalpoly(w, PH132) - THPIO4(Float32)
16+
p = p * cos(xn + x)
17+
return p
18+
end
19+
end
20+
121
function besselj1(x::Float64)
222
w = x
323
if x < 0
@@ -20,6 +40,27 @@ function besselj1(x::Float64)
2040
end
2141
end
2242

43+
function bessely1(x::Float32)
44+
if x <= 2.0f0
45+
if x <= zero(x)
46+
return error("Domain error: x <= 0")
47+
end
48+
z = x * x
49+
YO1 = 4.66539330185668857532f0
50+
w = (z - YO1) * x * evalpoly(z, YP32)
51+
w += TWOOPI(Float32) * (besselj1(x) * log(x) - inv(x))
52+
return w
53+
else
54+
q = inv(x)
55+
w = sqrt(q)
56+
p = w * evalpoly(q, MO132)
57+
w = q * q
58+
xn = q * evalpoly(w, PH132) - THPIO4(Float32)
59+
p = p * sin(xn + x)
60+
return p
61+
end
62+
end
63+
2364
function bessely1(x::Float64)
2465
if x <= 5.0
2566
if x< 0.0
@@ -40,6 +81,35 @@ function bessely1(x::Float64)
4081
end
4182
end
4283

84+
85+
const JP32 = (
86+
-3.405537384615824f-2, 1.937383947804541f-3,
87+
-4.541343896997497f-5, 6.009061827883699f-7,
88+
-4.878788132172128f-9
89+
)
90+
91+
92+
const YP32 = (
93+
4.202369946500099f-2, -2.641785726447862f-3,
94+
6.719543806674249f-5, -9.496460629917016f-7,
95+
8.061978323326852f-9
96+
)
97+
98+
99+
const MO132 = (
100+
7.978845453073848f-1, 4.976029650847191f-6,
101+
1.493389585089498f-1, 5.435364690523026f-3,
102+
-2.102302420403875f-1, 3.138238455499697f-1,
103+
-2.284801500053359f-1,6.913942741265801f-2,
104+
)
105+
106+
const PH132 = (
107+
3.749989509080821f-1, -1.637986776941202f-1,
108+
3.503787691653334f-1, -1.544842782180211f0,
109+
7.222973196770240f0, -2.485774108720340f1,
110+
5.073465654089319f1, -4.497014141919556f1,
111+
)
112+
43113
const RP = (
44114
3.68295732863852883286E15, -7.27494245221818276015E13,
45115
4.52228297998194034323E11, -8.99971225705559398224E8

test/besselj_test.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,15 @@ j1_SpecialFunctions = SpecialFunctions.besselj1.(big.(x))
2525
@assert j1_SpecialFunctions[1] isa BigFloat
2626

2727
j1_64 = besselj1.(Float64.(x))
28+
j1_32 = besselj1.(Float32.(x))
29+
2830

2931

3032
@test j1_64[1] isa Float64
33+
@test j1_32[1] isa Float32
34+
3135

3236
@test j1_64 j1_SpecialFunctions
37+
@test j1_32 j1_SpecialFunctions
38+
3339

test/bessely_test.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,14 @@ y1_SpecialFunctions = SpecialFunctions.bessely1.(big.(x))
2121
@assert y1_SpecialFunctions[1] isa BigFloat
2222

2323
y1_64 = bessely1.(Float64.(x))
24+
y1_32 = bessely1.(Float32.(x))
2425

2526

2627
@test y1_64[1] isa Float64
28+
@test y1_32[1] isa Float32
29+
2730

2831
@test y1_64 y1_SpecialFunctions
32+
@test y1_32 y1_SpecialFunctions
33+
2934

0 commit comments

Comments
 (0)