I know that to set the precision for numbers in Clojure I should use with-precision function and I know that it works only with BigDecimal values.
(defn bar-triang [[a b] [c d] [e f]]
(def cen [(/ (+ a c) 2.0) (/ (+ b d) 2.0)])
(def g (get cen 0))
(def h (get cen 1))
[(with-precision 4 (+ (bigdec g) (/ (- e g) 3M)))
(with-precision 4 (+ (bigdec h) (/ (- f h) 3M)))])
(bar-triang [4, 6], [12, 4], [10, 10])
=> [8.666666666666666 6.666666666666667]
Here, I've set the precision to 4, but REPL gives me the same number as before with more digits. Furthermore, I've coerced g and h to BigDecimal using bigdec, but problem remains the same. How can I solve this problem?
letlike(let [a 3] ..)- you effectevly declarecengandhas global accessible vars - birdspider