comp.lang.ada
 help / color / mirror / Atom feed
From: mheaney@on2.com (Matthew Heaney)
Subject: Re: Overhead for type conversions?
Date: 25 Jul 2003 08:34:02 -0700
Date: 2003-07-25T15:34:02+00:00	[thread overview]
Message-ID: <1ec946d1.0307250734.13c1a4d8@posting.google.com> (raw)
In-Reply-To: pan.2003.07.25.01.01.43.5699@mail.utexas.edu

"Bobby D. Bryant" <bdbryant@mail.utexas.edu> wrote in message news:<pan.2003.07.25.01.01.43.5699@mail.utexas.edu>...
> Given these declarations -
> 
>    type f1 is new float;
>    type f2 is new float;
> 
>    function "*"( left : in f1; right : in f2 ) return f1 is
>    begin
>       return( left * f1( right ) );
>    end "*";
> 
> and given that run-time range checks are enabled, should I expect my
> compiler to execute range checking code for each f1*f2 multiplication,
> or will the compiler conclude from the definitions that the two types
> are always convertible without error regardless of the specific value,
> and thus not generate any code for a range check?

Floating point types don't have constraint checks, unless the type is
declared that way.

The declaration

  type FT is digits 6;

doesn't have any range constraint, and I think that means that there
are no constraint checks.  I'm not sure about overflow checks.

However, the type declaration

   type FT is digits 6 range X .. Y;

does have a constraint, and so constraint checks apply.

This was one of the changes from Ada83 to Ada95: part of the ARG's
charter was to improve efficiency.

So to answer your question, I don't think there is any overhead for
the type conversion.  There are no constraint checks, because the type
doesn't have any constraints.  If the type had had constraints, then
constraint checks would apply.

Bob Duff answered a similar question about the floating point base
types, on CLA during 1997/10/03:

http://groups.google.com/groups?q=+%27base+group:comp.lang.ada+author:duff&hl=en&lr=&ie=UTF-8&selm=EHHp4E.AC4%40world.std.com&rnum=4

See also:

http://groups.google.com/groups?q=+%27base+group:comp.lang.ada+author:duff&hl=en&lr=&ie=UTF-8&selm=E4oE3q.1tq%40world.std.com&rnum=1

-Matt



  parent reply	other threads:[~2003-07-25 15:34 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-07-25  1:01 Overhead for type conversions? Bobby D. Bryant
2003-07-25  2:36 ` Robert I. Eachus
2003-07-25  7:12   ` Bobby D. Bryant
2003-07-25 15:34 ` Matthew Heaney [this message]
2003-07-25 18:28 ` Randy Brukardt
2003-07-26 15:54 ` Nick Roberts
2003-07-26 16:01   ` Warren W. Gay VE3WWG
2003-07-26 23:39     ` Bobby D. Bryant
2003-07-27 13:41       ` Loop Optimisation [was: Overhead for type conversions?] Nick Roberts
replies disabled

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