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 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,2c67233711f5206f X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news3.google.com!proxad.net!feeder1-2.proxad.net!u-picardie.fr!news.ecp.fr!news.jacob-sparre.dk!pnx.dk!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: float confusion Date: Tue, 14 Jul 2009 18:26:19 -0500 Organization: Jacob Sparre Andersen Message-ID: References: NNTP-Posting-Host: static-69-95-181-76.mad.choiceone.net X-Trace: munin.nbi.dk 1247614031 16458 69.95.181.76 (14 Jul 2009 23:27:11 GMT) X-Complaints-To: news@jacob-sparre.dk NNTP-Posting-Date: Tue, 14 Jul 2009 23:27:11 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5512 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579 Xref: g2news2.google.com comp.lang.ada:7061 Date: 2009-07-14T18:26:19-05:00 List-Id: Did you use -gnato? Gnat doesn't check integer overflow by default (one of the worst design decisions in GNAT, IMHO.) If you are just starting out, you ought to use -gnato -fstack_check on all of your compilations in order to get the behavior specified by the standard. (To be perfectly like the Ada Standard, you also need to use -gnatE, but that is much less likely to cause trouble.) Randy. "Rob Solomon" wrote in message news:sc2q55185rv4dhc8dk0feu0dvuq7887oul@4ax.com... >I ran this simple example thru GNAT and I'm confused by the result. > > -- conclusions from this pgm > -- integer type does not raise overflow constraint_error > -- natural and positive types do raise overflow constraint_error when > -- overflow is by multiplication, but not by addition. > > 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); > card32_IO.put(u2); > 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; > > My confusion is that float'digits is 6 and long_float'digits is 15 (I > already checked this). > > When I run this code, float grows to the full 13 digits before I stop > it. Why is that? > > And interestingly, I get overflow errors from the *2 statement but not > from self+self. I wonder if this occurs because this kind of overflow > is needed in the computation of random numbers. > > Thx