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

Method rationalize

src/jvm/clojure/lang/Numbers.java:341–356  ·  view source on GitHub ↗
(Number x)

Source from the content-addressed store, hash-verified

339}
340
341@WarnBoxedMath(false)
342static public Number rationalize(Number x){
343 if(x instanceof Float || x instanceof Double)
344 return rationalize(BigDecimal.valueOf(x.doubleValue()));
345 else if(x instanceof BigDecimal)
346 {
347 BigDecimal bx = (BigDecimal) x;
348 BigInteger bv = bx.unscaledValue();
349 int scale = bx.scale();
350 if(scale < 0)
351 return BigInt.fromBigInteger(bv.multiply(BigInteger.TEN.pow(-scale)));
352 else
353 return divide(bv, BigInteger.TEN.pow(scale));
354 }
355 return x;
356}
357
358//static Number box(int val){
359// return Integer.valueOf(val);

Callers

nothing calls this directly

Calls 5

fromBigIntegerMethod · 0.95
divideMethod · 0.95
multiplyMethod · 0.65
valueOfMethod · 0.45
doubleValueMethod · 0.45

Tested by

no test coverage detected