From: Martin Dowie <martin.dowie@btopenworld.com>
Subject: Re: Newbie Q
Date: Tue, 20 Sep 2005 05:48:00 +0000 (UTC)
Date: 2005-09-20T05:48:00+00:00 [thread overview]
Message-ID: <dgo7qf$7eo$1@nwrdmz02.dmz.ncs.ea.ibs-infra.bt.com> (raw)
In-Reply-To: <WXLXe.279644$5N3.247543@bgtnsc05-news.ops.worldnet.att.net>
Jim Rogers wrote:
>
> "Larry Luther" <larry.luther.nospam@dolby.com> 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.
or...
it's a very rare fixed point number, where the delta is 1.0.
type Degrees is delta 1.0 range 0.0 .. 100.0;
Could be a decimal type,
type Degrees is delta 1.0 digits 4 range 0.0 .. 100.0;
But more likely, it's a bug...
Cheers
-- Martin
next prev parent reply other threads:[~2005-09-20 5:48 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-09-20 1:11 Newbie Q Larry Luther
2005-09-20 4:09 ` Jim Rogers
2005-09-20 5:48 ` Martin Dowie [this message]
2005-09-20 11:52 ` Dr. Adrian Wrigley
2005-09-20 13:33 ` Martin Dowie
2005-09-21 17:24 ` Martin Dowie
2005-09-20 4:09 ` Samuel Tardieu
2005-09-20 5:52 ` Simon Wright
2005-09-20 6:28 ` Samuel Tardieu
2005-09-20 16:26 ` Martin Krischik
2005-09-21 7:27 ` Samuel Tardieu
2005-09-20 7:58 ` Dmitry A. Kazakov
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox