public static Ratio ToRatio(object x)
{
Ratio r = x as Ratio;
if (r != null)
return r;
BigDecimal bx = x as BigDecimal;
if ( bx != null )
{
int exp = bx.Exponent;
if (exp >= 0)
return new Ratio(bx.ToBigInteger(), BigInteger.One);
else
return new Ratio(bx.MovePointRight(-exp).ToBigInteger(), BigInteger.Ten.Power(-exp));
}
return new Ratio(ToBigInteger(x), BigInteger.One);
}