Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
(x-x !== 0.0) && 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
(x-x !== 0.0) && 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
(x-x !== 0.0) && 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
(x-x !== 0.0) && return NaN

if x > -pi4o2_h
if x <= 0
Expand Down
9 changes: 5 additions & 4 deletions test/numbers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2676,10 +2676,11 @@ 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))
end
end
end

import Base.^
Expand Down