| 322 | } |
| 323 | |
| 324 | @WarnBoxedMath(false) |
| 325 | static public Ratio toRatio(Object x){ |
| 326 | if(x instanceof Ratio) |
| 327 | return (Ratio) x; |
| 328 | else if(x instanceof BigDecimal) |
| 329 | { |
| 330 | BigDecimal bx = (BigDecimal) x; |
| 331 | BigInteger bv = bx.unscaledValue(); |
| 332 | int scale = bx.scale(); |
| 333 | if(scale < 0) |
| 334 | return new Ratio(bv.multiply(BigInteger.TEN.pow(-scale)), BigInteger.ONE); |
| 335 | else |
| 336 | return new Ratio(bv, BigInteger.TEN.pow(scale)); |
| 337 | } |
| 338 | return new Ratio(toBigInteger(x), BigInteger.ONE); |
| 339 | } |
| 340 | |
| 341 | @WarnBoxedMath(false) |
| 342 | static public Number rationalize(Number x){ |