Skip to content

Instantly share code, notes, and snippets.

@Vaguery
Created December 8, 2015 22:55
Show Gist options
  • Select an option

  • Save Vaguery/f132946f4382db375cee to your computer and use it in GitHub Desktop.

Select an option

Save Vaguery/f132946f4382db375cee to your computer and use it in GitHub Desktop.
I feel dirty
;;...
;; (:import [org.apfloat Apfloat ApfloatMath])
(def precision 100)
;;...
(defn pretty-much-equal?
"takes two Apfloat items, subtracts one from the other, and returns `true` if the absolute difference is less a threshold set to half the current precision"
[num1 num2]
(= -1 (.compareTo
(.subtract num1 num2)
(Apfloat. (str "1e-" (/ precision 2)) precision))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment