Skip to content

Commit 0d4b2a1

Browse files
author
oscarddssmith
committed
add comments
1 parent 02a158f commit 0d4b2a1

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

base/float.jl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -688,14 +688,20 @@ function hash(x::Real, h::UInt)
688688
den_z = trailing_zeros(den)
689689
den >>= den_z
690690
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
692694
if den == 1
695+
# left = ceil(log2(num)*2^pow)
693696
left = top_set_bit(abs(num)) + pow
697+
# 2^-1074 is the minimum Float64 so if the power is smaller, not a Float64
694698
if -1074 <= pow
695-
if pow >= 0
699+
if pow >= 0 # if pow is negative, it isn't an integer
696700
left <= 63 && return hash(Int64(num) << Int(pow), h)
697701
left <= 64 && !signbit(num) && return hash(UInt64(num) << Int(pow), h)
698702
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)
699705
left <= 1024 && left - pow <= 53 && return hash(ldexp(Float64(num), pow), h)
700706
end
701707
else

0 commit comments

Comments
 (0)