From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,9d03247c8459fa7b X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!news.glorb.com!wn13feed!worldnet.att.net!bgtnsc05-news.ops.worldnet.att.net.POSTED!53ab2750!not-for-mail Newsgroups: comp.lang.ada Subject: Re: Newbie Q From: Jim Rogers References: User-Agent: Xnews/5.04.25 Message-ID: Date: Tue, 20 Sep 2005 04:09:26 GMT NNTP-Posting-Host: 12.73.183.75 X-Complaints-To: abuse@worldnet.att.net X-Trace: bgtnsc05-news.ops.worldnet.att.net 1127189366 12.73.183.75 (Tue, 20 Sep 2005 04:09:26 GMT) NNTP-Posting-Date: Tue, 20 Sep 2005 04:09:26 GMT Organization: AT&T Worldnet Xref: g2news1.google.com comp.lang.ada:4931 Date: 2005-09-20T04:09:26+00:00 List-Id: "Larry Luther" wrote in news:RkJXe.771 $OC2.358@newssvr21.news.prodigy.com: > > I saw the following example in "Ada Programming" Wiki book: > > if Temperature >= Degrees'(40.0) then > Put_Line ("It's extremely hot"); > elsif Temperature in Degrees'(30.0 .. 39.0) then > Put_Line ("It's hot"); > elsif Temperature in Degrees'(20.0 .. 29.0) then > Put_Line ("It's warm"); > elsif Temperature in Degrees'(10.0 .. 19.0) then > Put_Line ("It's cool"); > elsif temperature in Degrees'(0.0 .. 9.0) then > Put_Line ("It's cold"); > else > Put_Line ("It's freezing"); > end if; > > What happens at 29.5 degrees? > I'm assuming that "Temperature in Degrees'(20.0 .. 29.0)" will test > the interval Temperature >= 20.0 through Temperature <= 29.0. > So temperatures between 29.0 and 30.0 will be considered "freezing". You are correct. This example exhibits a similar error between 29.0 and 30.0 degrees, between 19.0 and 20.0 degrees, and between 9.0 and 10.0 degrees. The person writing this program was clearly thinking in terms of integer arithmetic when he or she was dealing with either floating point of fixed point arithmetic. The example does not indicate whether Degrees is a fixed point or floating point type. This example would work better with a fixed point type than with a floating point type because one can always know what the minimum delta between two fixed point numbers is. The same cannot be said of a floating point number. The example properly demonstrates the syntax of the if..elsif..else syntax while also creating a logical error. Jim Rogers