Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix rem2pi for non-finite arguments #46163

Merged
merged 6 commits into from
Jul 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions base/math.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1239,7 +1239,7 @@ julia> rem2pi(7pi/4, RoundDown)
"""
function rem2pi end
function rem2pi(x::Float64, ::RoundingMode{:Nearest})
isnan(x) && return NaN
isfinite(x) || return NaN

abs(x) < pi && return x

Expand All @@ -1264,7 +1264,7 @@ function rem2pi(x::Float64, ::RoundingMode{:Nearest})
end
end
function rem2pi(x::Float64, ::RoundingMode{:ToZero})
isnan(x) && return NaN
isfinite(x) || return NaN

ax = abs(x)
ax <= 2*Float64(pi,RoundDown) && return x
Expand All @@ -1291,7 +1291,7 @@ function rem2pi(x::Float64, ::RoundingMode{:ToZero})
copysign(z,x)
end
function rem2pi(x::Float64, ::RoundingMode{:Down})
isnan(x) && return NaN
isfinite(x) || return NaN

if x < pi4o2_h
if x >= 0
Expand Down Expand Up @@ -1322,7 +1322,7 @@ function rem2pi(x::Float64, ::RoundingMode{:Down})
end
end
function rem2pi(x::Float64, ::RoundingMode{:Up})
isnan(x) && return NaN
isfinite(x) || return NaN

if x > -pi4o2_h
if x <= 0
Expand Down
10 changes: 6 additions & 4 deletions test/numbers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2676,10 +2676,12 @@ end
end

@testset "PR #36420 $T" for T in (Float16, Float32, Float64)
@test rem2pi(T(NaN), RoundToZero) === T(NaN)
@test rem2pi(T(NaN), RoundNearest) === T(NaN)
@test rem2pi(T(NaN), RoundDown) === T(NaN)
@test rem2pi(T(NaN), RoundUp) === T(NaN)
for r in (RoundToZero, RoundNearest, RoundDown, RoundUp)
for x in (Inf, -Inf, NaN, -NaN)
@test isnan(rem2pi(T(x), r))
oscardssmith marked this conversation as resolved.
Show resolved Hide resolved
@test rem2pi(T(x), r) isa T
end
end
end

import Base.^
Expand Down