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

Method matchNumber

src/jvm/clojure/lang/LispReader.java:475–524  ·  view source on GitHub ↗
(String s)

Source from the content-addressed store, hash-verified

473
474
475private static Object matchNumber(String s){
476 Matcher m = intPat.matcher(s);
477 if(m.matches())
478 {
479 if(m.group(2) != null)
480 {
481 if(m.group(8) != null)
482 return BigInt.ZERO;
483 return Numbers.num(0);
484 }
485 boolean negate = (m.group(1).equals("-"));
486 String n;
487 int radix = 10;
488 if((n = m.group(3)) != null)
489 radix = 10;
490 else if((n = m.group(4)) != null)
491 radix = 16;
492 else if((n = m.group(5)) != null)
493 radix = 8;
494 else if((n = m.group(7)) != null)
495 radix = Integer.parseInt(m.group(6));
496 if(n == null)
497 return null;
498 BigInteger bn = new BigInteger(n, radix);
499 if(negate)
500 bn = bn.negate();
501 if(m.group(8) != null)
502 return BigInt.fromBigInteger(bn);
503 return bn.bitLength() < 64 ?
504 Numbers.num(bn.longValue())
505 : BigInt.fromBigInteger(bn);
506 }
507 m = floatPat.matcher(s);
508 if(m.matches())
509 {
510 if(m.group(4) != null)
511 return new BigDecimal(m.group(1));
512 return Double.parseDouble(s);
513 }
514 m = ratioPat.matcher(s);
515 if(m.matches())
516 {
517 String numerator = m.group(1);
518 if (numerator.startsWith("+")) numerator = numerator.substring(1);
519
520 return Numbers.divide(Numbers.reduceBigInt(BigInt.fromBigInteger(new BigInteger(numerator))),
521 Numbers.reduceBigInt(BigInt.fromBigInteger(new BigInteger(m.group(2)))));
522 }
523 return null;
524}
525
526static private IFn getMacro(int ch){
527 if(ch < macros.length)

Callers 1

readNumberMethod · 0.95

Calls 8

numMethod · 0.95
fromBigIntegerMethod · 0.95
divideMethod · 0.95
reduceBigIntMethod · 0.95
bitLengthMethod · 0.80
negateMethod · 0.65
equalsMethod · 0.45
longValueMethod · 0.45

Tested by

no test coverage detected