comp.lang.ada
 help / color / mirror / Atom feed
From: Rob Solomon <usenet@drrob1-noreply.com>
Subject: Re: float confusion
Date: Tue, 14 Jul 2009 20:03:57 -0400
Date: 2009-07-14T20:03:57-04:00	[thread overview]
Message-ID: <0u6q55lvsmo3urasars18pti1g4tcajqek@4ax.com> (raw)
In-Reply-To: 510054e8-9abf-4a6e-87f2-3385e573b1c2@g31g2000yqc.googlegroups.com

On Tue, 14 Jul 2009 16:50:20 -0700 (PDT), Adam Beneschan
<adam@irvine.com> wrote:

>> with Ada.Text_IO;
>> with Ada.Integer_Text_IO;
>> with Ada.Float_Text_IO;
>> use Ada.Text_IO;
>> use Ada.Integer_Text_IO;
>> use Ada.Float_Text_IO;
>>
>> � �procedure SimpleCompute is
>>
>> � �X : Integer := 1;
>> � �c : Integer := 0; �-- counter
>> � �N : Natural := 1;
>> � �P : Positive := 1;
>> � �F : Float := 1.0;
>>
>> � �begin
>> � �put_line("X C N P F");
>> � �loop
>> � � put(X);
>> � � put(c,3);
>> � � put(n);
>> � � put(' ');
>> � � put(p);
>> � � put(' ');
>> � � put(f,15,0,0);
>> � � New_Line;
>> � � X := X * 2;
>> � � n := n * 2;
>> � � p := p + p;
>> � � f := f * 2.0;
>> � � c := c +1;
>> � � exit when c > 40;
>> � �end loop;
>> � �exception
>> � � � when constraint_error =>
>> � � � � �n := 1;
>> � �end simplecompute;
>>
>> And interestingly, I get overflow errors from the *2 statement but not
>> from self+self.
>
>How can you tell?  Your above example gives you no way to tell what
>line you get an overflow on.  And the way it's written, if you got an
>overflow on X := X*2, the exception would take you out of the loop and
>you'd never get to the p := p+p statement for the same value (since it
>looks like X=n=p will always be true at the beginning of the loop).
>

Ok.  I got this example from the online tutorial and I kept modifying
it to try something new.  Before I experimented w/  exception
handling, I was getting constraint_error exceptions.  

But Jeff Carter above explained that was I was seeing was really range
checking effects and not overflow effects.  That helped me understand
what was going on.




  reply	other threads:[~2009-07-15  0:03 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-14 22:46 float confusion Rob Solomon
2009-07-14 23:23 ` Jeffrey R. Carter
2009-07-14 23:26 ` Randy Brukardt
2009-07-14 23:50 ` Adam Beneschan
2009-07-15  0:03   ` Rob Solomon [this message]
2009-07-15  0:18     ` Adam Beneschan
replies disabled

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