1+ ; Copyright (c) Mark Engelberg, Rich Hickey and contributors. All rights reserved.
2+ ; The use and distribution terms for this software are covered by the
3+ ; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
4+ ; which can be found in the file epl-v10.html at the root of this distribution.
5+ ; By using this software in any fashion, you are agreeing to be bound by
6+ ; the terms of this license.
7+ ; You must not remove this notice, or any other, from this software.
8+
19; ;; math.clj: math functions that deal intelligently with the various
210; ;; types in Clojure's numeric tower, as well as math functions
311; ;; commonly found in Scheme implementations.
@@ -53,21 +61,21 @@ exact-integer-sqrt - Implements a math function from the R6RS Scheme
5361 returns the floor of the square root and the \" remainder\" .
5462" }
5563 clojure.math.numeric-tower )
56-
57- ; ; so this code works with both 1.2.x and 1.3.0:
64+
65+ ; ; so this code works with both 1.2.x and 1.3.0:
5866(def ^{:private true } minus (first [-' -]))
59- (def ^{:private true } mult (first [*' *]))
67+ (def ^{:private true } mult (first [*' *]))
6068(def ^{:private true } plus (first [+' +]))
6169(def ^{:private true } dec* (first [dec' dec]))
62- (def ^{:private true } inc* (first [inc' inc]))
63-
70+ (def ^{:private true } inc* (first [inc' inc]))
71+
6472; ; feature testing macro, based on suggestion from Chas Emerick:
6573(defmacro when-available
6674 [sym & body]
6775 (try
6876 (when (resolve sym)
6977 (list* 'do body))
70- (catch ClassNotFoundException _#)))
78+ (catch ClassNotFoundException _#)))
7179
7280(defn- expt-int [base pow]
7381 (loop [n pow, y (num 1 ), z base]
@@ -85,9 +93,9 @@ Returns an exact number if the base is an exact number and the power is an integ
8593 (cond
8694 (pos? pow) (expt-int base pow)
8795 (zero? pow) (cond
88- (= (type base) BigDecimal) 1M
96+ (= (type base) BigDecimal) 1M
8997 (= (type base) java.math.BigInteger) (java.math.BigInteger. " 1" )
90- (when-available clojure.lang.BigInt (= (type base) clojure.lang.BigInt))
98+ (when-available clojure.lang.BigInt (= (type base) clojure.lang.BigInt))
9199 (when-available clojure.lang.BigInt (bigint 1 ))
92100 :else 1 )
93101 :else (/ 1 (expt-int base (minus pow))))
@@ -138,8 +146,8 @@ round always returns an integer. Rounds up for values exactly in between two in
138146 (integer-length [n] (.bitLength n))
139147 (sqrt [n] (sqrt-integer n)))
140148
141- (when-available
142- clojure.lang.BigInt
149+ (when-available
150+ clojure.lang.BigInt
143151 (extend-type
144152 clojure.lang.BigInt MathFunctions
145153 (floor [n] n)
0 commit comments