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,start X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news2.google.com!news.glorb.com!news2.glorb.com!news-in-01.newsfeed.easynews.com!easynews!core-easynews-01!easynews.com!en-nntp-08.dc1.easynews.com.POSTED!not-for-mail From: Rob Solomon Newsgroups: comp.lang.ada Subject: float confusion Message-ID: X-Newsreader: Forte Agent 4.2/32.1118 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@easynews.com Organization: Forte Inc. http://www.forteinc.com/apn/ X-Complaints-Info: Please be sure to forward a copy of ALL headers otherwise we will be unable to process your complaint properly. Date: Tue, 14 Jul 2009 18:46:01 -0400 Xref: g2news2.google.com comp.lang.ada:7058 Date: 2009-07-14T18:46:01-04:00 List-Id: 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