Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fixed reading of ratios prefixed by + and added tests

Signed-off-by: Stuart Halloway <stu@thinkrelevance.com>
  • Loading branch information...
commit 78d62cd0b35f3ea6ee0ea98815c2810e74364326 1 parent 0437539
@cosmin cosmin authored stuarthalloway committed
View
5 src/jvm/clojure/lang/LispReader.java
@@ -399,7 +399,10 @@ else if((n = m.group(7)) != null)
m = ratioPat.matcher(s);
if(m.matches())
{
- return Numbers.divide(Numbers.reduceBigInt(BigInt.fromBigInteger(new BigInteger(m.group(1)))),
+ String numerator = m.group(1);
+ if (numerator.startsWith("+")) numerator = numerator.substring(1);
+
+ return Numbers.divide(Numbers.reduceBigInt(BigInt.fromBigInteger(new BigInteger(numerator))),
Numbers.reduceBigInt(BigInt.fromBigInteger(new BigInteger(m.group(2)))));
}
return null;
View
6 test/clojure/test_clojure/reader.clj
@@ -21,7 +21,7 @@
(:use [clojure.instant :only [read-instant-date
read-instant-calendar
read-instant-timestamp]])
- (:import clojure.lang.BigInt
+ (:import [clojure.lang BigInt Ratio]
java.io.File
java.util.TimeZone))
@@ -273,6 +273,10 @@
(is (instance? BigDecimal -1.0M))
(is (instance? BigDecimal -1.M))
+
+ (is (instance? Ratio 1/2))
+ (is (instance? Ratio -1/2))
+ (is (instance? Ratio +1/2))
)
;; Characters
Please sign in to comment.
Something went wrong with that request. Please try again.