Skip to content

Commit 87d89f7

Browse files
oscardssmithKristofferC
authored andcommitted
fix rem2pi for non-finite arguments (#46163)
(cherry picked from commit 73c1eeb)
1 parent 4fa7980 commit 87d89f7

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

base/math.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,7 +1131,7 @@ julia> rem2pi(7pi/4, RoundDown)
11311131
"""
11321132
function rem2pi end
11331133
function rem2pi(x::Float64, ::RoundingMode{:Nearest})
1134-
isnan(x) && return NaN
1134+
isfinite(x) || return NaN
11351135

11361136
abs(x) < pi && return x
11371137

@@ -1156,7 +1156,7 @@ function rem2pi(x::Float64, ::RoundingMode{:Nearest})
11561156
end
11571157
end
11581158
function rem2pi(x::Float64, ::RoundingMode{:ToZero})
1159-
isnan(x) && return NaN
1159+
isfinite(x) || return NaN
11601160

11611161
ax = abs(x)
11621162
ax <= 2*Float64(pi,RoundDown) && return x
@@ -1183,7 +1183,7 @@ function rem2pi(x::Float64, ::RoundingMode{:ToZero})
11831183
copysign(z,x)
11841184
end
11851185
function rem2pi(x::Float64, ::RoundingMode{:Down})
1186-
isnan(x) && return NaN
1186+
isfinite(x) || return NaN
11871187

11881188
if x < pi4o2_h
11891189
if x >= 0
@@ -1214,7 +1214,7 @@ function rem2pi(x::Float64, ::RoundingMode{:Down})
12141214
end
12151215
end
12161216
function rem2pi(x::Float64, ::RoundingMode{:Up})
1217-
isnan(x) && return NaN
1217+
isfinite(x) || return NaN
12181218

12191219
if x > -pi4o2_h
12201220
if x <= 0

test/numbers.jl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2612,10 +2612,12 @@ end
26122612
end
26132613

26142614
@testset "PR #36420 $T" for T in (Float16, Float32, Float64)
2615-
@test rem2pi(T(NaN), RoundToZero) === T(NaN)
2616-
@test rem2pi(T(NaN), RoundNearest) === T(NaN)
2617-
@test rem2pi(T(NaN), RoundDown) === T(NaN)
2618-
@test rem2pi(T(NaN), RoundUp) === T(NaN)
2615+
for r in (RoundToZero, RoundNearest, RoundDown, RoundUp)
2616+
for x in (Inf, -Inf, NaN, -NaN)
2617+
@test isnan(rem2pi(T(x), r))
2618+
@test rem2pi(T(x), r) isa T
2619+
end
2620+
end
26192621
end
26202622

26212623
import Base.^

0 commit comments

Comments
 (0)