fix hashing of rationals (#9264)

Fixes #9264, also replace `x*2.0^y` by faster `ldexp(x,y)`.
I suspect there was some reason I didn't just use `abs` here, but I can't think of it now. It's possible this was faster.