fix hashing of rationals (#9264)

Fixes #9264, also replace `x*2.0^y` by faster `ldexp(x,y)`.
If `ifelse(n < 0, oftype(n,-n), n)` really is faster, we should probably make that `abs`.