From 7324e84999431c3b6aaf151241696034b7301468 Mon Sep 17 00:00:00 2001 From: rsiddharth Date: Sat, 30 Apr 2016 20:31:19 +0000 Subject: Add one/eight.scm Exercise 1.8. --- one/eight.scm | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 one/eight.scm (limited to 'one') diff --git a/one/eight.scm b/one/eight.scm new file mode 100644 index 0000000..fb944e7 --- /dev/null +++ b/one/eight.scm @@ -0,0 +1,38 @@ +;;; Under Creative Commons Attribution-ShareAlike 4.0 +;;; International. See +;;; . + +(define-module (one eight) + #:export (cube double + div-three improve + good-enough? cbrt-iter + cbrt-sicp)) + +(use-modules (one six)) + +(define (cube x) + (* (square x) x)) + +(define (double x) + (* 2 x)) + +(define (div-three x) + (/ x 3.0)) + +(define (improve y x) + (div-three (+ (/ x (square y)) + (double y)))) + +(define (good-enough? y x) + (< (abs (- (cube y) x)) + 0.001)) + +(define (cbrt-iter y x) + (if (good-enough? y x) + y + (cbrt-iter (improve y x) + x))) + +(define (cbrt-sicp x) + (cbrt-iter 1.0 x)) + -- cgit v1.2.3