Solution to SICP Exercise 2.10

Structure and Interpretation of Computer Programs

One solution to Exercise 2.10:

(define (spans-zero? x)
(not (or (positive? (lower-bound x))
(negative? (upper-bound x)))))

(define (div-interval x y)
(if (spans-zero? y)
(error "Divisor spans zero" y)
(mul-interval x
(make-interval (/ 1.0 (upper-bound y))
(/ 1.0 (lower-bound y))))))

%d bloggers like this: