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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,1d8973f9fd947fbd,start X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-09-20 15:50:12 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!news-han1.dfn.de!news-fra1.dfn.de!news.man.poznan.pl!pwr.wroc.pl!panorama.wcss.wroc.pl!hebisch From: hebisch@math.uni.wroc.pl (Waldek Hebisch) Newsgroups: comp.lang.ada Subject: Is this a gnat bug? Date: 20 Sep 2003 22:50:11 GMT Organization: Politechnika Wroclawska Message-ID: NNTP-Posting-Host: hera.math.uni.wroc.pl X-Trace: panorama.wcss.wroc.pl 1064098211 21157 156.17.86.1 (20 Sep 2003 22:50:11 GMT) X-Complaints-To: abuse@news.pwr.wroc.pl NNTP-Posting-Date: 20 Sep 2003 22:50:11 GMT X-Newsreader: TIN [version 1.2 PL2] Xref: archiver1.google.com comp.lang.ada:42721 Date: 2003-09-20T22:50:11+00:00 List-Id: I am trying to convert a sequence of eight bytes to a fixed point number. For testing I put bytes in an array. I first collect bytes in a modular type and then assign the result to an integer (I have eight bytes in big endian order, but the actual number should be small). When number formed from 4 lower order bytes is out of range I get CONSTRAINT_ERROR but if only higher order bytes are non-zero I get just zero result. I would expect CONSTRAINT_ERROR always when any of higher order bytes is non-zero. With both gnat-3.14p and gnat from gcc-3.3 the program below prints huge number for 'pp' and 0.0 for 'price'. with Ada.Text_IO; procedure tstnum is type fx15_2 is delta 0.01 range -9999999999999.99 .. 9999999999999.99 ; type price_type is delta 0.01 digits 6; procedure getnum(num : out price_type) is type ll is mod 2**64; type ip is range 0 .. 1000000 ; type byteind is range 0 .. 7; bytes : array (byteind) of integer range 0 .. 255 := (0..3 => 247 , 4..7=>0); pp : ll := 0 ; pp1 : ip; begin for i in bytes'range loop pp := pp * 256; pp := pp + ll(bytes(i)); end loop; Ada.Text_IO.Put_Line("pp = " & ll'image(pp)); pp1 := ip(pp); -- Should range check ?? num := price_type(fx15_2(pp1)/100); end; price : price_type; begin getnum(price); Ada.Text_IO.Put_Line("price = " & price_type'image(price)); end tstnum; -- Waldek Hebisch hebisch@math.uni.wroc.pl or hebisch@hera.math.uni.wroc.pl