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,f6204cee2f9f77e2 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-01-21 10:48:58 PST Newsgroups: comp.lang.ada Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newshosting.com!news-xfer2.atl.newshosting.com!uunet!dca.uu.net!ash.uu.net!world!news From: Robert A Duff Subject: Re: Constraint_Error in arithmetic expressions User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 Sender: news@world.std.com (Mr Usenet Himself) Message-ID: Date: Tue, 21 Jan 2003 18:48:02 GMT Content-Type: text/plain; charset=us-ascii References: NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Organization: The World Public Access UNIX, Brookline, MA Xref: archiver1.google.com comp.lang.ada:33305 Date: 2003-01-21T18:48:02+00:00 List-Id: Michal Nowak writes: > On 2003-01-12 at 23:37 Robert A Duff wrote: > > >> Suppose that if I declare: > >> type T is range 1 .. 200; > >> A : T := 150; > >> B : T := 150; > >> the compiler may choose 1 byte (0 .. 255) or 2 bytes (0 .. 65535) for > >> example, for the base subtype. > > > >No. "is range" declares a signed integer type, and for signed integers, > >the base range is always symmetric about zero (or has an extra negative > >value). So the minimal base range the compiler can choose in this case > >is -200..200. It can choose a wider range. Compilers usually choose a > >range that is supported by the hardware. > > Oh, in fact, I found appropriate RM section. > > Now comes another curious question - > Why the base range is symmetric about zero? I don't know. It seems like an overly hardware-oriented rule, to me. Why not make the minimal range for T'Base be exactly T? If you want a bigger base range, you should say so. > Is it because that it is for signed integer? Are there any reasons > for it? > I'm asking, because suppose I have a 16 bit machine. > Now I want to declare: > type T is range 2**16 - 10 .. 2**16 - 1; > > but it is not possible. Well, if the compiler supports 32-bit integers on that 16-bit machine (which is likely), then it *is* possible. But in general, arithmetic will then have to use 32-bit intermediate results (except in cases where the compiler can prove it's not necessary). >... However, if the base type could be in range > 0 .. 2**16 - 1 it could be possible. If the hardware supports unsigned arithmetic with efficient overflow detection. > Thank you for your previous answer, You're welcome. - Bob