Skip to content

Commit 08326eb

Browse files
committed
[Breaking] Change default rem rounding mode to RoundToZero
The previous default was `RoundNearest`, which was inconsistent with the behavior for Base float types, as noted in issue 112. The move to `RoundToZero` is potentially subtly breaking but worthwhile for behavioral consistency with Base. Fixes issue 112
1 parent f9cb67b commit 08326eb

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

‎src/Quadmath.jl‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,9 +346,9 @@ end
346346
Float128(@quad_ccall(@autoql(atan2)(x::Cfloat128, y::Cfloat128)::Cfloat128))
347347

348348
Base.Integer(x::Float128) = Int(x)
349-
@assume_effects :foldable Base.rem(x::Float128, y::Float128, ::RoundingMode{:Nearest}=RoundNearest) =
349+
@assume_effects :foldable Base.rem(x::Float128, y::Float128, ::RoundingMode{:Nearest}) =
350350
Float128(@quad_ccall(@autoql(remainder)(x::Cfloat128, y::Cfloat128)::Cfloat128))
351-
@assume_effects :foldable Base.rem(x::Float128, y::Float128, ::RoundingMode{:ToZero}) =
351+
@assume_effects :foldable Base.rem(x::Float128, y::Float128, ::RoundingMode{:ToZero}=RoundToZero) =
352352
Float128(@quad_ccall(@autoql(fmod)(x::Cfloat128, y::Cfloat128)::Cfloat128))
353353

354354
if VERSION < v"1.14.0-DEV.2070"

‎test/rounding.jl‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,10 @@ end
310310
end
311311

312312
# These tests were copied from Julia. License is MIT: https://julialang.org/license.
313+
@testset "rounding consistency with Base" begin
314+
@test rem(prevfloat(Float128(1)), Float128(1)) == prevfloat(Float128(1))
315+
@test mod(prevfloat(Float128(1)), Float128(1)) == prevfloat(Float128(1))
316+
end
313317
@testset "rem(::Float128, ::Float128, ::RoundingMode)" begin
314318
T = Float128
315319
@test rem(T(1), T(2), RoundToZero) == 1

0 commit comments

Comments
 (0)