Skip to content

Instantly share code, notes, and snippets.

@manishym
Created December 22, 2011 04:20
Show Gist options
  • Save manishym/1508906 to your computer and use it in GitHub Desktop.
Save manishym/1508906 to your computer and use it in GitHub Desktop.
Square root by newtons method
(defun square-root (x)
(labels (
(try (guess)
(if (good-enough? guess)
guess
(try (improve guess))))
(good-enough? (guess)
(if (< (abs (- guess (/ x guess))) eps) guess nil ))
(improve (guess)
(average guess (/ x guess))))
(try 1.0)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment