diff --git a/src/besselk.jl b/src/besselk.jl index 0335546..ba1382f 100644 --- a/src/besselk.jl +++ b/src/besselk.jl @@ -243,7 +243,11 @@ end Scaled modified Bessel function of the second kind of order nu, ``K_{nu}(x)*e^{x}``. """ -function besselkx(nu, x::T) where T <: Union{Float32, Float64} +besselkx(nu::Real, x::Real) = _besselkx(nu, float(x)) + +_besselkx(nu, x::Float16) = Float16(_besselkx(nu, Float32(x))) + +function _besselkx(nu, x::T) where T <: Union{Float32, Float64} # dispatch to avoid uniform expansion when nu = 0 iszero(nu) && return besselk0x(x) diff --git a/test/besseli_test.jl b/test/besseli_test.jl index 6374008..e20dfe9 100644 --- a/test/besseli_test.jl +++ b/test/besseli_test.jl @@ -92,6 +92,7 @@ t = [besseli(m, x) for m in m, x in x] t = [besselix(m, x) for m in m, x in x] @test t[10] isa Float64 @test t ≈ [SpecialFunctions.besselix(m, x) for m in m, x in x] +@test besselix(10, Float16(1.0)) isa Float16 ## Tests for besselk diff --git a/test/besselk_test.jl b/test/besselk_test.jl index aaa8de6..cc8b037 100644 --- a/test/besselk_test.jl +++ b/test/besselk_test.jl @@ -122,6 +122,7 @@ end # test Float16 @test besselk(10, Float16(1.0)) isa Float16 +@test besselkx(10, Float16(1.0)) isa Float16 # test Inf @test iszero(besselk(2, Inf))