Skip to content

Instantly share code, notes, and snippets.

@redsquirrel
Forked from jimweirich/gist:189270
Created September 22, 2009 21:46
Show Gist options
  • Save redsquirrel/191462 to your computer and use it in GitHub Desktop.
Save redsquirrel/191462 to your computer and use it in GitHub Desktop.
(define (cbrt-iter guess x)
(if (good-enough? guess x)
guess
(cbrt-iter (improve guess x)
x)))
(define (improve guess x)
(/ (+ (/ x (* guess guess)) (* 2 guess)) 3))
(define (good-enough? guess x)
(< (abs (- (cube guess) x)) 0.001))
(define (cube x) (* x x x))
(define (cbrt x)
(cbrt-iter 1.0 x))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment