Skip to content

Commit 9d7cb20

Browse files
committed
refactor F64, BigFloat
1 parent 68e531e commit 9d7cb20

File tree

3 files changed

+16
-23
lines changed

3 files changed

+16
-23
lines changed

src/asymptotics.jl

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -180,13 +180,6 @@ function _α_αp_poly_30(v, x::T) where T
180180
end
181181

182182
# the following are the coefficients in exact fractions which can be used for arbitrary precision calculations
183-
function besselj_large_argument(v, x::BigFloat)
184-
T = BigFloat
185-
α, αp = _α_αp_asymptotic(v, x)
186-
xn = fma(v, PIO2(T), PIO4(T))
187-
b = SQ2OPI(T) / sqrt(αp * x)
188-
return cos- xn)*b
189-
end
190183
function _α_αp_asymptotic(v, x::BigFloat)
191184
T = BigFloat
192185
xinv = inv(x)^2

src/besselj.jl

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -203,17 +203,16 @@ end
203203

204204
# for moderate size arguments of x and v this has relative errors ~9e-15
205205
# for large arguments relative errors ~1e-13
206-
function besselj_large_argument(v, x::T) where T <: Float64
206+
function besselj_large_argument(v, x::T) where T
207207
α, αp = _α_αp_asymptotic(v, x)
208-
xn = fma(v, PIO2(T), PIO4(T))
209208
b = SQ2OPI(T) / sqrt(αp * x)
210-
return cos_sum(α, -xn)*b
211-
end
212-
function besselj_large_argument(v, x::T) where T <: Float32
213-
α, αp = _α_αp_asymptotic(v, x)
214-
xn = fma(v, PIO2(T), PIO4(T))
215-
b = SQ2OPI(T) / sqrt(αp * x)
216-
return cos(Float64(α) - Float64(xn))*b
209+
210+
S, C = sincos(PIO2(T)*v)
211+
Sα, Cα = sincos(α)
212+
s1 = (C - S) *
213+
s2 = (C + S) *
214+
215+
return SQ2O2(T) * (s1 + s2) * b
217216
end
218217

219218
# generally can only use for x < 4.0
@@ -258,14 +257,12 @@ function besselj_debye(v, x)
258257
S = promote_type(T, Float64)
259258
x = S(x)
260259

261-
vmx = fma(v,v, -x^2)
262-
vdx = v/x
263-
b = sqrt(vmx)
264-
265-
n = v * log(vdx + sqrt(vdx^2 - 1)) - b
260+
vmx = (v + x) * (v x)
261+
vs = sqrt(vmx)
262+
n = fma(v, -log(x / (v + vs)), -vs)
266263

267-
coef = SQ1O2PI(S) * exp(-n) / sqrt(b)
268-
p = v / b
264+
coef = SQ1O2PI(S) * exp(-n) / sqrt(vs)
265+
p = v / vs
269266
p2 = v^2 / vmx
270267

271268
return coef * Uk_poly_Jn(p, v, p2, T)

src/math_constants.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const SQPIO2(::Type{BigFloat}) = big"1.25331413731550025120788264240552262650349
55
const SQ1O2PI(::Type{BigFloat}) = big"0.3989422804014326779399460599343818684758586311649346576659258296706579258993008"
66
const SQ2OPI(::Type{BigFloat}) = big"0.7978845608028653558798921198687637369517172623298693153318516593413158517986017"
77
const PIO4(::Type{BigFloat}) = big"0.7853981633974483096156608458198757210492923498437764552437361480769541015715495"
8+
const SQ2O2(::Type{BigFloat}) = big"0.707106781186547524400844362104849039284835937688474036588339868995366239231051"
89

910
const PIO4(::Type{Float64}) = .78539816339744830962
1011
const PIO2(::Type{Float64}) = 1.5707963267948966
@@ -14,7 +15,9 @@ const TWOOPI(::Type{Float64}) = 0.6366197723675814
1415
const SQPIO2(::Type{Float64}) = 1.25331413731550025
1516
const SQ1O2PI(::Type{Float64}) = 0.3989422804014327
1617
const SQ2PI(::Type{Float64}) = 2.5066282746310007
18+
const SQ2O2(::Type{Float64}) = 0.7071067811865476
1719

1820
const PIO4(::Type{Float32}) = 0.78539816339744830962f0
1921
const TWOOPI(::Type{Float32}) = 0.636619772367581343075535f0
2022
const THPIO4(::Type{Float32}) = 2.35619449019234492885f0
23+
const SQ2O2(::Type{Float32}) = 0.7071067811865476f0

0 commit comments

Comments
 (0)