Skip to content

Instantly share code, notes, and snippets.

@kballenegger
Created March 3, 2012 01:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kballenegger/759d8403cd16b6415cb1 to your computer and use it in GitHub Desktop.
Save kballenegger/759d8403cd16b6415cb1 to your computer and use it in GitHub Desktop.
(defn derivative [precision-magnitude f]
(let [dx (expt 10 (- 0 precision-magnitude 1))]
#(let [d (/ (- (f (+ % dx)) (f %)) dx)]
(/ (round (* d precision-magnitude)) precision-magnitude))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment