Skip to content

Commit

Permalink
Fix Bessel functions for very large order (#4366)
Browse files Browse the repository at this point in the history
Our version of openlibm uses a recurrence relation to build higher order
Bessel functions from j0 and j1. For orders greater than int32_t, the
recurrence loop never runs thanks to integer overflow in the loop index.
The fix here is to simply throw a DomainError for such enormous values
of the order of the Bessel function.
  • Loading branch information
jiahao committed Feb 22, 2014
1 parent 08315f1 commit b2fea25
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions base/math.jl
Original file line number Diff line number Diff line change
Expand Up @@ -595,9 +595,12 @@ function besselj(nu::Float64, z::Complex128)
end

function besselj(nu::Integer, x::FloatingPoint)
nu > typemax(Int32) && throw(DomainError())
return oftype(x, ccall((:jn, libm), Float64, (Cint, Float64), nu, x))
end

function besselj(nu::Integer, x::Float32)
nu > typemax(Int32) && throw(DomainError())
return ccall((:jnf, libm), Float32, (Cint, Float32), nu, x)
end

Expand Down

0 comments on commit b2fea25

Please sign in to comment.