Why languages like Haskell and Clojure adopt rational as type? Why would I use Rational instead of Float or Double?
Why languages like Haskell and Clojure adopt rational as type? Why would I use Rational instead of Float or Double?
Float and Double are binary floating-point types, so there are rounding issues. Many numbers with decimal parts can not be expressed exactly. Rational people do not have this problem.
But the biggest reason is that certain problems are best expressed by fractions, usually working with integer values divided by integers with fixed or arithmetic precision.