You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Math functions that deal intelligently with the various
types in Clojure's numeric tower, as well as math functions
commonly found in Scheme implementations.
Functions included:
(expt x y) - x to the yth power
(abs n) - absolute value of n
(gcd m n) - greatest common divisor of m and n
(lcm m n) - least common multiple of m and n
(floor x) - round down
(ceil x) - round up
(round x) - round to nearest
(sqrt x) - square root, exact if possible
(exact-integer-sqrt k) returns floor of square root and the "remainder"
(nsexample.core
(:require [clojure.math.numeric-tower :as math]))
(defn-sqr"Uses the numeric tower expt to square a number"
[x]
(math/expt x 2))
(defneuclidean-squared-distance"Computes the Euclidean squared distance between two sequences"
[a b]
(reduce + (map (comp sqr -) a b)))
(defneuclidean-distance"Computes the Euclidean distance between two sequences"
[a b]
(math/sqrt (euclidean-squared-distance a b)))
(let [a [123581321]
b [024681012]]
(euclidean-distance a b))
;;=> 9.643650760992955
Refer to docstrings in the clojure.math.numeric-tower namespace for
additional documentation.