A compile-time rational number.

If you explicitely specify the denominator, be sure to use an *unsigned* integer literal (e.g. 2u) – even though the template accepts only unsigned integers anyway, this seems to make a difference.

Note: This was tailored to the specific needs of the units library, and isn't optimized at all.

template Rational (
int n
uint d = 1u
) {
enum gcd_;


static assert(is(Rational!(2, 1u) == Rational!2));
static assert(is(Rational!(6, 3u) == Rational!2));