Skip to content

Commit

Permalink
fix sinc(Inf+Inf*im) (#37547)
Browse files Browse the repository at this point in the history
* fix sinc(Inf+Inf*im)

* added cosc test
  • Loading branch information
stevengj committed Sep 13, 2020
1 parent 9b7c2b8 commit 90f8b17
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
6 changes: 2 additions & 4 deletions base/special/trig.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1079,10 +1079,8 @@ sinc(x::Integer) = iszero(x) ? one(x) : zero(x)
_sinc(x::Number) = iszero(x) ? one(x) : isinf_real(x) ? zero(x) : sinpi(x)/(pi*x)
_sinc_threshold(::Type{Float64}) = 0.001
_sinc_threshold(::Type{Float32}) = 0.05f0
@inline function _sinc(x::Union{T,Complex{T}}) where {T<:Union{Float32,Float64}}
a = fastabs(x)
return a < _sinc_threshold(T) ? evalpoly(x^2, (T(1), -T(pi)^2/6, T(pi)^4/120)) : isinf_real(a) ? zero(x) : sinpi(x)/(pi*x)
end
@inline _sinc(x::Union{T,Complex{T}}) where {T<:Union{Float32,Float64}} =
fastabs(x) < _sinc_threshold(T) ? evalpoly(x^2, (T(1), -T(pi)^2/6, T(pi)^4/120)) : isinf_real(x) ? zero(x) : sinpi(x)/(pi*x)
_sinc(x::Float16) = Float16(_sinc(Float32(x)))
_sinc(x::ComplexF16) = ComplexF16(_sinc(ComplexF32(x)))

Expand Down
3 changes: 3 additions & 0 deletions test/math.jl
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,9 @@ end

@test sinc(Inf + 3im) == 0
@test cosc(Inf + 3im) == 0

@test isequal(sinc(Inf + Inf*im), NaN + NaN*im)
@test isequal(cosc(Inf + Inf*im), NaN + NaN*im)
end

# issue #37227
Expand Down

0 comments on commit 90f8b17

Please sign in to comment.