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

Method matchNumber

src/jvm/clojure/lang/EdnReader.java:314–363  ·  view source on GitHub ↗
(String s)

Source from the content-addressed store, hash-verified

312
313
314private static Object matchNumber(String s){
315 Matcher m = intPat.matcher(s);
316 if(m.matches())
317 {
318 if(m.group(2) != null)
319 {
320 if(m.group(8) != null)
321 return BigInt.ZERO;
322 return Numbers.num(0);
323 }
324 boolean negate = (m.group(1).equals("-"));
325 String n;
326 int radix = 10;
327 if((n = m.group(3)) != null)
328 radix = 10;
329 else if((n = m.group(4)) != null)
330 radix = 16;
331 else if((n = m.group(5)) != null)
332 radix = 8;
333 else if((n = m.group(7)) != null)
334 radix = Integer.parseInt(m.group(6));
335 if(n == null)
336 return null;
337 BigInteger bn = new BigInteger(n, radix);
338 if(negate)
339 bn = bn.negate();
340 if(m.group(8) != null)
341 return BigInt.fromBigInteger(bn);
342 return bn.bitLength() < 64 ?
343 Numbers.num(bn.longValue())
344 : BigInt.fromBigInteger(bn);
345 }
346 m = floatPat.matcher(s);
347 if(m.matches())
348 {
349 if(m.group(4) != null)
350 return new BigDecimal(m.group(1));
351 return Double.parseDouble(s);
352 }
353 m = ratioPat.matcher(s);
354 if(m.matches())
355 {
356 String numerator = m.group(1);
357 if (numerator.startsWith("+")) numerator = numerator.substring(1);
358
359 return Numbers.divide(Numbers.reduceBigInt(BigInt.fromBigInteger(new BigInteger(numerator))),
360 Numbers.reduceBigInt(BigInt.fromBigInteger(new BigInteger(m.group(2)))));
361 }
362 return null;
363}
364
365static private IFn getMacro(int ch){
366 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