We are required to solve the problem of division by zero in the interval division operation in column 2.10.
When talking about Ben bitdiddle, a professional programmer, after reading Alyssa's work, he raised the question of Division from zero. Everyone should pay attention to the person named Ben, who will keep appearing next to him, as long as this person mentioned something, it is generally right. His role is positioned as a computer cool, but it is the kind of cool people that can often be seen in the office, and there are more cool people in the future.
Division by zero for Interval operations is easy to handle. You only need to determine whether the divisor is zero. If the divisor is zero, an error is returned. For an interval, the so-called zero is that the interval spans 0, and the start point is negative, and the end point is positive.
After understanding this, it is easy to write code:
(define (div-interval x y) (if (< (* (upper-bound y) (lower-bound y)) 0) (error "Div 0:" y)) (mul-interval x(make-interval (/ 1.0 (upper-bound y)) (/ 1.0 (lower-bound y)))))
Okay. The problem solving is over.
Abstract: Division by zero in interval Division