SICP Exercises (2.10) Summary of solving problems: the problem of dividing zero in interval division

Source: Internet
Author: User

SICP Exercise 2.10 requires us to deal with the problem of zero in interval division operations.


In the title of a professional program ape Ben Bitdiddle looked at the work of Alyssa after the question of zero, we pay attention to this person called Ben, will continue to appear this person, only if the person mentioned things are usually right, his role is a computer cattle man, It's just the kind of cow that the office can always see, and there's more bull in the back.


For the interval operation in addition to the zero problem, processing is also relatively simple, only need to infer whether the divisor is zero, the divisor is zero error. For an interval, the so-called zero is the interval across 0, and then a direct point is that the starting point is negative, the end point is a positive number.


Understanding the code will be very easy to write in the future:


(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))))



OK, the problem is over.


SICP Exercises (2.10) Summary of solving problems: the problem of dividing zero in interval division

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.