下面是求以 1.12 为底,2.7 的对数。本方法极其低效,仅仅标记一下以备以后参考。
(ns t
(:require [clojure.contrib.generic.math-functions :as math]))
(defn abs [x]
(if (< x 0) (* -1 x) x))
(defn close-enough? [delta]
#(< (abs (- %1 %2)) delta))
(defn calc-log [lg lg-level acc-stack]
(let [acc (math/pow 1.12 lg)
close? (close-enough? 0.00000000000000000001M)
lg-inc (/ 1 (math/pow 10 lg-level))
finer-lg-inc (/ 1 (math/pow 10 (inc lg-level)))]
(if (close? acc 2.7)
lg
(if (> acc 2.7)
(recur (+ (- lg lg-inc) finer-lg-inc) (inc lg-level) acc-stack)
(recur (+ lg lg-inc) lg-level (conj acc-stack acc))))))
(println (calc-log 1 0 []))