]> git.rkrishnan.org Git - sicp.git/blobdiff - src/sicp/utils.clj
Solution to 4.33. This had been difficult to get right, though conceptually it was
[sicp.git] / src / sicp / utils.clj
index 3ab538c21ee69c20fc21d67698a5fbe9cd257d16..516b0141eba9306c16ded1167c800cb8d5407110 100644 (file)
     a
     (gcd b (rem a b))))
 
-(defn average [a b]
-  (/ (+ a b) 2.0))
+(defn average [ & coll]
+  (/ (reduce + coll)
+     (float (count coll))))
+
+(defn approx-equal [x y]
+  (< (abs (- x y)) 0.00001))
+
+(defn error [^String string]
+  (throw (Exception. string)))
 
 (defmacro microbench
   " Evaluates the expression n number of times, returning the average