Why does the `Irrational` type exist

I recently stumbled upon an error writing x->zeros(typeof(x), (2, 2)), when I applied this to π. I quickly found that this was related to the Irrational type, which seems to be kind of a headache: Zero(π) and one(π) are false and true? discusses this. This leads to weird behaviours: for instance, in my case it was Irrational(zero(π)) throwing an error (because zero(π) is false).

So is there a reason for the type to exist?

Fundamentally, the goal behind the Irrationals is to seamlessly promote to higher-precision values as needed. For example, you can write deg2rad(deg) = π * deg/180 without worrying about types — this will use a higher-precision value of pi if deg is a BigFloat.

6 Likes