Why use Rational type?

1

Why languages like Haskell and Clojure adopt rational as type? Why would I use Rational instead of Float or Double?

    
asked by anonymous 25.05.2017 / 00:31

1 answer

5

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.

    
25.05.2017 / 00:36