diff options
-rw-r--r-- | src/clj/clojure/core.clj | 12 | ||||
-rw-r--r-- | test/clojure/test_clojure/numbers.clj | 3 |
2 files changed, 15 insertions, 0 deletions
diff --git a/src/clj/clojure/core.clj b/src/clj/clojure/core.clj index e2cf386e..1f46b487 100644 --- a/src/clj/clojure/core.clj +++ b/src/clj/clojure/core.clj @@ -2402,6 +2402,18 @@ "Returns true if n is a Ratio" [n] (instance? clojure.lang.Ratio n)) +(defn numerator + "Returns the numerator part of a Ratio." + {:tag BigInteger} + [r] + (.numerator #^clojure.lang.Ratio r)) + +(defn denominator + "Returns the denominator part of a Ratio." + {:tag BigInteger} + [r] + (.denominator #^clojure.lang.Ratio r)) + (defn decimal? "Returns true if n is a BigDecimal" [n] (instance? BigDecimal n)) diff --git a/test/clojure/test_clojure/numbers.clj b/test/clojure/test_clojure/numbers.clj index 72bb7d03..2283ccf4 100644 --- a/test/clojure/test_clojure/numbers.clj +++ b/test/clojure/test_clojure/numbers.clj @@ -433,3 +433,6 @@ Math/pow overflows to Infinity." "[J" (long-array 1) (longs (long-array 1 1)))) +(deftest test-ratios + (is (= (denominator 1/2) 2)) + (is (= (numerator 1/2) 1)))
\ No newline at end of file |