Why use the rational type?

Asked

Viewed 70 times

1

Why do languages like Haskell and Clojure adopt rationale as a type? Why would I use Rationale instead of Float or Double?

1 answer

5


Float and Double are binary floating point types, so there are rounding problems. Many numbers with decimal parts cannot be expressed exactly. Rationals do not have this problem.

But the biggest reason is that certain problems are better expressed by fractions, in general they work with integer values divided by other integers with a fixed precision or arithmetic.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.