From: "Jeff Carter" <jcgoogle@earthlink.net>
Subject: Re: When floating point result intervals span the boundary - what value is selected?
Date: 5 Mar 2006 11:12:59 -0800
Date: 2006-03-05T11:12:59-08:00 [thread overview]
Message-ID: <1141585979.022216.245190@z34g2000cwc.googlegroups.com> (raw)
In-Reply-To: <IvjOf.443$Cc3.88@trnddc08>
Justin Gombos wrote:
>
> 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.
In Ada, exceptions are raised. Please do not use "throw" when
discussing Ada exceptions.
No. Floating-point operations only deal with a fixed number of bits in
the mantissa. This gives at least the decimal number of digits given in
the type declaration. When you add 2 numbers with different exponents,
the smaller one is scaled to have the same exponent as the larger one
before adding. When a small number like 1.0E-20 is scaled to match a
much larger number like 1.0, the smaller number becomes zero. Thus, the
result of the addition is 1.0.
> What exactly is going on in this case? The calculations must produce
> a result that is greater than 1.0, at least initially.
No, they don't.
> 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.
The first line adds zero to 1.0, giving 1.0, as described above. The
second line yields the next model number of the base type > 1.0. This
number exists, but is not in the range of the subtype, so
Constraint_Error is raised.
--
Jeff Carter
jrcarter commercial-at adm [period | full stop] org
next prev parent reply other threads:[~2006-03-05 19:12 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
2006-03-05 19:12 ` Jeff Carter [this message]
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