Julia: Error in hash of Rational{Int}

Created on 30 Jan 2018  路  4Comments  路  Source: JuliaLang/julia

There is a subtle bug in the hashing code of Rational{<:BigInteger64}, in the file hashing2.jl, line 158:

            return hash(ldexp(Float64(num),pow))

This does not pass the incoming hash argument h, and thus, while it produces the correct result when just comparing hash(3//2) with hash(1.5), it does not produce the same result for hash(3//2,h) and hash(1.5,h) for any non-zero h.

I would fix myself but I am traveling and hence not in my normal workflow.

Pinging @StefanKarpinski as I think he wrote the hashing code.

good first issue help wanted rationals

Most helpful comment

Note that we're not going to backport this to 0.4 or 0.5 at this point, but I've tagged this anyway since it could be backported to those releases.

All 4 comments

Good catch! Yes, this seems like a simple enough fix 鈥撀爅ust pass the h argument on this line:

https://github.com/JuliaLang/julia/blob/ac389b016702666853bdb80d521a02977705bba1/base/hashing2.jl#L158

I.e. change it to

return hash(ldexp(Float64(num), pow), h)

Then add a test to verify that this is done correctly.

Note that we're not going to backport this to 0.4 or 0.5 at this point, but I've tagged this anyway since it could be backported to those releases.

What prevents it from being backported to 0.3 though?

Only the lack of a label. I drew the line at creating a label for backports that we will never do.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Keno picture Keno  路  3Comments

tkoolen picture tkoolen  路  3Comments

ararslan picture ararslan  路  3Comments

iamed2 picture iamed2  路  3Comments

wilburtownsend picture wilburtownsend  路  3Comments