comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: Constraint_Error in arithmetic expressions
Date: Tue, 21 Jan 2003 18:48:02 GMT
Date: 2003-01-21T18:48:02+00:00	[thread overview]
Message-ID: <wcck7gy8hlp.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: mailman.8.1042983074.265.comp.lang.ada@ada.eu.org

Michal Nowak <vinnie@inetia.pl> 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



      reply	other threads:[~2003-01-21 18:48 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-01-12 12:36 Constraint_Error in arithmetic expressions Michal Nowak
2003-01-12 23:37 ` Robert A Duff
2003-01-19 13:41   ` Michal Nowak
2003-01-21 18:48     ` Robert A Duff [this message]
replies disabled

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