MCPcopy Index your code
hub / github.com/clojure/clojure / toRatio

Method toRatio

src/jvm/clojure/lang/Numbers.java:324–339  ·  view source on GitHub ↗
(Object x)

Source from the content-addressed store, hash-verified

322}
323
324@WarnBoxedMath(false)
325static 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)
342static public Number rationalize(Number x){

Callers 9

addMethod · 0.80
multiplyMethod · 0.80
divideMethod · 0.80
quotientMethod · 0.80
remainderMethod · 0.80
equivMethod · 0.80
ltMethod · 0.80
lteMethod · 0.80
gteMethod · 0.80

Calls 2

toBigIntegerMethod · 0.95
multiplyMethod · 0.65

Tested by

no test coverage detected