Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Yes, all floating numbers are rational. (It's also true that they are all reals but i get your point.)


They aren’t pure rational either. They are a subset of rational numbers.


I think that's more of how one frames it, no? Like you won't be able to store any arbitrary rational in a float, as you'd need arbitrarily large storage for that. But all the numbers a float can store are rationals (so excluding all the fanciful IEEE-754 features of course).


It's not so much the need for arbitrary storage, the problem is that even easy rationals can't be expressed in the IEEE floats

Take realistic::Rational::fraction(1, 3) ie one third. Floats can't represent that, but we don't need a whole lot of space for it, we're just storing the numerator and denominator.

If we say we actually want f64, the 8 byte IEEE float, we get only a weak approximation, 6004799503160661/18014398509481984 because 3 doesn't go neatly into any power of 2.

Edited: An earlier version of this comment provided the 32-bit fraction 11184811/33554432 instead of the 64-bit one.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: