| 295 | } |
| 296 | |
| 297 | @WarnBoxedMath(false) |
| 298 | static BigDecimal toBigDecimal(Object x){ |
| 299 | if(x instanceof BigDecimal) |
| 300 | return (BigDecimal) x; |
| 301 | else if(x instanceof BigInt) |
| 302 | { |
| 303 | BigInt bi = (BigInt) x; |
| 304 | if(bi.bipart == null) |
| 305 | return BigDecimal.valueOf(bi.lpart); |
| 306 | else |
| 307 | return new BigDecimal(bi.bipart); |
| 308 | } |
| 309 | else if(x instanceof BigInteger) |
| 310 | return new BigDecimal((BigInteger) x); |
| 311 | else if(x instanceof Double) |
| 312 | return new BigDecimal(((Number) x).doubleValue()); |
| 313 | else if(x instanceof Float) |
| 314 | return new BigDecimal(((Number) x).doubleValue()); |
| 315 | else if(x instanceof Ratio) |
| 316 | { |
| 317 | Ratio r = (Ratio)x; |
| 318 | return (BigDecimal)divide(new BigDecimal(r.numerator), r.denominator); |
| 319 | } |
| 320 | else |
| 321 | return BigDecimal.valueOf(((Number) x).longValue()); |
| 322 | } |
| 323 | |
| 324 | @WarnBoxedMath(false) |
| 325 | static public Ratio toRatio(Object x){ |