File tree Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Original file line number Diff line number Diff line change @@ -688,14 +688,20 @@ function hash(x::Real, h::UInt)
688
688
den_z = trailing_zeros (den)
689
689
den >>= den_z
690
690
pow += num_z - den_z
691
- # handle values representable as Int64, UInt64, Float64
691
+ # If the real is an Int64, UInt64, or Float64, hash as those types.
692
+ # To be an Integer the denominator must be 1 and the power must be positive.
693
+ # To be a Float64
692
694
if den == 1
695
+ # left = ceil(log2(num)*2^pow)
693
696
left = top_set_bit (abs (num)) + pow
697
+ # 2^-1074 is the minimum Float64 so if the power is smaller, not a Float64
694
698
if - 1074 <= pow
695
- if pow >= 0
699
+ if pow >= 0 # if pow is negative, it isn't an integer
696
700
left <= 63 && return hash (Int64 (num) << Int (pow), h)
697
701
left <= 64 && ! signbit (num) && return hash (UInt64 (num) << Int (pow), h)
698
702
end # typemin(Int64) handled by Float64 case
703
+ # 2^1024 is the maximum Float64 so if the power is greater, not a Float64
704
+ # Float64s only have 53 mantisa bits (including implicit bit)
699
705
left <= 1024 && left - pow <= 53 && return hash (ldexp (Float64 (num), pow), h)
700
706
end
701
707
else
You can’t perform that action at this time.
0 commit comments