Skip to content
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
11 changes: 11 additions & 0 deletions src/DecFP.jl
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,17 @@ function Base.:(==)(dec::DecimalFloatingPoint, rat::Rational)
end
end

Base.:(==)(dec::T, flt::Union{Float16,Float32,Float64}) where {T<:DecimalFloatingPoint} = dec == T(flt, RoundUp) == T(flt, RoundDown)
Base.:>(dec::T, flt::Union{Float16,Float32,Float64}) where {T<:DecimalFloatingPoint} = dec > T(flt, RoundDown)
Base.:<(dec::T, flt::Union{Float16,Float32,Float64}) where {T<:DecimalFloatingPoint} = dec < T(flt, RoundUp)
Base.:(>=)(dec::T, flt::Union{Float16,Float32,Float64}) where {T<:DecimalFloatingPoint} = dec >= T(flt, RoundUp)
Base.:(<=)(dec::T, flt::Union{Float16,Float32,Float64}) where {T<:DecimalFloatingPoint} = dec <= T(flt, RoundDown)
Base.:(==)(flt::Union{Float16,Float32,Float64}, dec::T) where {T<:DecimalFloatingPoint} = dec == flt
Base.:>(flt::Union{Float16,Float32,Float64}, dec::T) where {T<:DecimalFloatingPoint} = dec < flt
Base.:<(flt::Union{Float16,Float32,Float64}, dec::T) where {T<:DecimalFloatingPoint} = dec > flt
Base.:(>=)(flt::Union{Float16,Float32,Float64}, dec::T) where {T<:DecimalFloatingPoint} = dec <= flt
Base.:(<=)(flt::Union{Float16,Float32,Float64}, dec::T) where {T<:DecimalFloatingPoint} = dec >= flt

# used for next/prevfloat:
const pinf128 = _parse(Dec128, "+Inf")
const minf128 = _parse(Dec128, "-Inf")
Expand Down
35 changes: 35 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,38 @@ for T in (Dec32, Dec64, Dec128)
@test T(7) / T(100) == 7//100
@test T(7) / T(300) != 7//300

for Tf in (Float64, Float32, Float16)
@test parse(T, "0.1") != parse(Tf, "0.1")
@test parse(Tf, "0.1") != parse(T, "0.1")
@test parse(T, "0.7") != parse(Tf, "0.7")
@test parse(Tf, "0.7") != parse(T, "0.7")
if Tf == Float16
@test parse(T, "0.1") > parse(Tf, "0.1")
@test parse(T, "0.1") >= parse(Tf, "0.1")
@test parse(Tf, "0.1") < parse(T, "0.1")
@test parse(Tf, "0.1") <= parse(T, "0.1")
@test parse(T, "0.7") < parse(Tf, "0.7")
@test parse(T, "0.7") <= parse(Tf, "0.7")
@test parse(Tf, "0.7") > parse(T, "0.7")
@test parse(Tf, "0.7") >= parse(T, "0.7")
else
@test parse(T, "0.1") < parse(Tf, "0.1")
@test parse(T, "0.1") <= parse(Tf, "0.1")
@test parse(Tf, "0.1") > parse(T, "0.1")
@test parse(Tf, "0.1") >= parse(T, "0.1")
@test parse(T, "0.7") > parse(Tf, "0.7")
@test parse(T, "0.7") >= parse(Tf, "0.7")
@test parse(Tf, "0.7") < parse(T, "0.7")
@test parse(Tf, "0.7") <= parse(T, "0.7")
end
@test parse(T, "0.5") == parse(Tf, "0.5")
@test parse(T, "0.5") <= parse(Tf, "0.5")
@test parse(T, "0.5") >= parse(Tf, "0.5")
@test parse(Tf, "0.5") == parse(T, "0.5")
@test parse(Tf, "0.5") <= parse(T, "0.5")
@test parse(Tf, "0.5") >= parse(T, "0.5")
end

for x = -5.0:0.25:5.0, y = -5.0:0.25:5.0
@test isequal(rem(T(x), T(y)), rem(x, y))
@test isequal(rem(T(x), T(y), RoundNearest), rem(x, y, RoundNearest))
Expand Down Expand Up @@ -335,6 +367,9 @@ end

@test Float64(d64"1e100") == 1e100

# issue #79
@test d64"1e100" != 1e100

# issue #93
@test parse(Dec64, "3935767060.093896713") == d64"3.935767060093897e9" ==
Dec64(d128"3935767060.093896713")