boostorg / multiprecision

Boost.Multiprecision
Boost Software License 1.0
188 stars 112 forks source link

Random hash_value for mpfr_float(0) #593

Open fintarin opened 5 months ago

fintarin commented 5 months ago

The hash_value for mpfr_float constructed from zero int is random. Thus, hash_value(mpfr_float(0)) != hash_value(mpfr_float(0)). The problem is related to data()[0]._mpfr_d - code.

When debugging hash_function(mpfr_float(0)) I get various random _mpfr_d such as:

I assume that _mpfr_d holds an uninitialised values when the number is initialised with zero. So to fix this, you should check is_zero in the hash_value function. Also, the same problem can occur with other special values such as infinity and nan.