Skip to content

Commit 5b84e7e

Browse files
TotalVerbomus
authored andcommitted
Fix hash support (#22)
1 parent 3c9285f commit 5b84e7e

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/FixedPointDecimals.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ using Compat
3232
import Base: reinterpret, zero, one, abs, sign, ==, <, <=, +, -, /, *, div, rem, divrem,
3333
fld, mod, fldmod, fld1, mod1, fldmod1, isinteger, typemin, typemax,
3434
realmin, realmax, print, show, string, convert, parse, promote_rule, min, max,
35-
trunc, round, floor, ceil, eps, float, widemul
35+
trunc, round, floor, ceil, eps, float, widemul, decompose
3636

3737
const BitInteger = Union{Int8, UInt8, Int16, UInt16, Int32, UInt32, Int64,
3838
UInt64, Int128, UInt128}
@@ -475,6 +475,7 @@ coefficient(::Type{FD{T, f}}) where {T, f} = T(10)^f
475475
coefficient(fd::FD{T, f}) where {T, f} = coefficient(FD{T, f})
476476
value(fd::FD) = fd.i
477477

478-
Base.hash(fd::FD{T, f}, h::UInt) where {T, f} = Base.hash(BigFloat(fd), h)
478+
# for generic hashing
479+
decompose(fd::FD) = decompose(Rational(fd))
479480

480481
end

test/runtests.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -947,6 +947,8 @@ end
947947
@test hash(fd1) == hash(fd2)
948948
@test hash(fd1) != hash(fd3)
949949
@test hash(fd1) != hash(fd1.i)
950+
@test hash(FD2(1//10)) == hash(1//10)
951+
@test hash(FD2(1//10)) hash(0.1)
950952
end
951953
end
952954

0 commit comments

Comments
 (0)