public static object rationalize(object x)
{
if (x is float)
return rationalize(BigDecimal.Create((float)x));
if (x is double)
return rationalize(BigDecimal.Create((double)x));
BigDecimal bx = (BigDecimal)x;
if (bx != null)
{
int exp = bx.Exponent;
if (exp >= 0)
return BigInt.fromBigInteger(bx.ToBigInteger());
else
return divide(bx.MovePointRight(-exp).ToBigInteger(), BigInteger.Ten.Power(-exp));
}
return x;
}