<< Previous exercise (2.9) | Index | Next exercise (2.11) >>
Couldn't we simply check if upper and lower bound are equal? Also, what happens here when dividing by an interval that starts at a negative and ends at a positive?
(div-interval (make-interval 0 1) (make-interval -2 2))
I propose this solution:
(define (div-interval x y)
(if (= (upper-bound y) (lower-bound y))
(error "division by zero interval")
(mul-interval x
(make-interval (/ 1.0 (upper-bound y))
(/ 1.0 (lower-bound y))))))
The answer above(vi) misunderstand the question, if the interval is zero(upper-bound = lower-bound), that's alright, it won't cause any problem, the problem is the interval spans zero (upper-bound > 0, and lower-bound < 0), then if the dividend happens to be zero, it will cause problem. The first answer(jz) is correct.
Basically, we're just using the error keyword.