comp.lang.ada
 help / color / mirror / Atom feed
From: Justin Gombos <rpbkbq.xax.gld@uluv.kbq>
Subject: Re: When floating point result intervals span the boundary - what value is selected?
Date: Sat, 04 Mar 2006 16:46:32 GMT
Date: 2006-03-04T16:46:32+00:00	[thread overview]
Message-ID: <IvjOf.443$Cc3.88@trnddc08> (raw)
In-Reply-To: TPQNf.1393$Bj7.1143@newsread2.news.pas.earthlink.net

On 2006-03-03, Jeffrey R. Carter <spam@spam.com> wrote:
> Justin Gombos wrote:
>
>> Oversized : Sine_Type := Sine_Type'Last + Sine_Type'Small;
>
> This is odd; 'Small is defined only for fixed-point types (ARM
> K). Maybe this is compiler specific. You should probably use
> 'Model_Small.
>
> Anyway, since 'Small gives 2.58494E-26 and you probably have 6
> digits of accuracy, 1.0 + 'Small = 1.0. Remember that "+" is defined
> for the base type.

I repeated the experiment adding Sine_Type'Model_Small instead.  If
Sine_Type'Last is the highest possible model number in the set, how is
it possible to add Sine_Type'Model_Small to that without throwing a
constraint error?  While I expect the "+" operation to complete
because it's working with Sine_Type'Base, I expect the assignment of
that result to Oversized to fail.  It must be converted back to a
model number prior to storage, and the resulting model number is out
of range.

>> Well_Oversized : constant Float := Float(Sine_Type'Last) +
>>                                    Float(Sine_Type'Small * 500000.0);
>
> Similarly here, 5.0E5 * 2.58494E-26 ~ 1.3E-20, and 1.0 + 1.3E-20 =
> 1.0 with 6 digits of accuracy.

What exactly is going on in this case?  The calculations must produce
a result that is greater than 1.0, at least initially.  Is the runtime
logic rounding toward zero when the difference is within accuracy
constraints?  Does an Ada compiler have the option to throw a
constraint error?

I know I'm missing something here, because I expect the following two
lines to have the exact same result:

   Oversized : Sine_Type := Sine_Type'Last + Sine_Type'Model_Number;
   Oversized : Sine_Type := Sine_Type'Succ(Sine_Type'Last);

The first line runs without error, and the second line throws a
constraint error.

-- 
PM instructions: do a C4esar Ciph3r on my address; retain punctuation.



  reply	other threads:[~2006-03-04 16:46 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-03-03  1:30 When floating point result intervals span the boundary - what value is selected? Justin Gombos
2006-03-03  2:55 ` haley
2006-03-03  5:51 ` Jeffrey R. Carter
2006-03-04 16:46   ` Justin Gombos [this message]
2006-03-05 19:12     ` Jeff Carter
2006-03-05 19:13     ` Jeff Carter
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox