fix hashing of rationals (#9264)