Skip to content

Commit

Permalink
fixup! faster hashing by avoiding UB
Browse files Browse the repository at this point in the history
  • Loading branch information
vtjnash committed Oct 15, 2020
1 parent f08d525 commit ebb267a
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions base/abstractset.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ julia> union!(a, 1:2:8);
julia> a
Set{Int64} with 5 elements:
7
5
4
7
3
5
1
```
"""
Expand Down
4 changes: 2 additions & 2 deletions base/float.jl
Original file line number Diff line number Diff line change
Expand Up @@ -563,12 +563,12 @@ let Tf = Float64, Tu = UInt64, Ti = Int64
# see comments on trunc and hash(Real, UInt)
if $(Tf(typemin(Ti))) <= x < $(Tf(typemax(Ti)))
xi = fptosi($Ti, x)
if xi == x
if isequal(xi, x)
return hash(xi, h)
end
elseif $(Tf(typemin(Tu))) <= x < $(Tf(typemax(Tu)))
xu = fptoui($Tu, x)
if xu == x
if isequal(xu, x)
return hash(xu, h)
end
elseif isnan(x)
Expand Down
1 change: 1 addition & 0 deletions test/hashing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ for T = types, S = types, x = vals
#println("$(typeof(b)) $b")
@test isequal(a, b) == (hash(a) == hash(b))
end
@test hash(0.0) != hash(-0.0)

# issue #8619
@test hash(nextfloat(2.0^63)) == hash(UInt64(nextfloat(2.0^63)))
Expand Down
2 changes: 1 addition & 1 deletion test/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1608,7 +1608,7 @@ end

# issue #27680
@test showstr(Set([(1.0,1.0), (2.0,2.0), (3.0, 3.0)])) == (sizeof(Int) == 8 ?
"Set([(3.0, 3.0), (2.0, 2.0), (1.0, 1.0)])" :
"Set([(1.0, 1.0), (3.0, 3.0), (2.0, 2.0)])" :
"Set([(1.0, 1.0), (2.0, 2.0), (3.0, 3.0)])")

# issue #27747
Expand Down

0 comments on commit ebb267a

Please sign in to comment.