Arlen:
https://github.com/Arlen/phobos/blob/std_rational/std/rational.d
docs: http://arlen.github.com/phobos/std_rational.html
I'd like a good Rational in Phobos.
From your code:
private template isSignedIntegral(T)
{
enum isSignedIntegral = isIntegral!T && isSigned!T;
}
...
struct Rational(T) if (isSignedIntegral!T)
{
static if (is(T == immutable) || is(T == const))
{
private enum bool mutableT = false;
}
else
{
private enum bool mutableT = true;
}
static if (mutableT)
{
private T numerator;
private T denominator = 1;
private bool dirty;
}
else
{
private T numerator, denominator;
@disable this();
}
...
A Rational should accept T as BigInt too.
And isn't it better for the Rational constructor to simplify the
arguments (calling an optimized GCD)? See this implementation
(that doesn't use an optimized GCD):
http://rosettacode.org/wiki/Arithmetic/Rational#D
Bye,
bearophile