comp.lang.ada
 help / color / mirror / Atom feed
From: matthew_heaney@acm.org (Matthew Heaney)
Subject: Re: Renaming Fixed Point Mutiplicative operator in Ada 95
Date: 1998/05/22
Date: 1998-05-22T00:00:00+00:00	[thread overview]
Message-ID: <matthew_heaney-ya023680002205980838060001@news.ni.net> (raw)
In-Reply-To: 01bd8589$5fa05a00$440029a1@m00rq900


In article <01bd8589$5fa05a00$440029a1@m00rq900>, "Stuart Hutchesson"
<shutch@innotts.co.uk> wrote:

>>  b) you test for it explicitly
>> 
>>     if z = 0 then
>>       ....
>>     else
>>         a := y /z;
>>     end if;
>> 
>If you are suggesting that all divisions are guarded by a test for
>denonimator non-zero - then wouln't the most obvious place for that test be
>within the division operator itself! Otherwise you have a massive
>review/verification effort to check that all divisions are guarded! If it
>is inside the operator then that test is done once.  Also
> there is the question of the code that has to be placed inside the "if"
>side of the check.
>
>Plus you have to consider all the other guards that have to be placed
>around both multipy and divide operations for overflow of the destination
>type etc.  The neatest and most cost-effective solution is to put them
>inside an overridden operator.

Will you settle for "inside an operation"?  How about this

generic
   type LT is delta <>;
   type RT is delta <>;
   type Result_Type is delta <>:
function Generic_Divide 
   (L : LT; R : RT) return Result_Type;

function Generic_Divide ... is
begin
   if R = 0.0 then
      return Result_Type'Last;
   end if;

   declare
      Result : Result_Type'Base := L/R;
   begin
       if Result in Result_Type then
          return Result;
       else
          return Result'Last;
      end if;
   end;
end Generic_Divide;

Then you could do something like

function Div is new Generic_Divide (...);

Z := Div (X, Y);

If this works (I didn't try to compile it or anything), then would it be an
acceptable compromise?  (It was stated earlier that this is a fix to legacy
code, so perhaps not.  But would it work in principle?)




  reply	other threads:[~1998-05-22  0:00 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-05-19  0:00 Renaming Fixed Point Mutiplicative operator in Ada 95 Stuart Hutchesson
1998-05-19  0:00 ` Matthew Heaney
1998-05-20  0:00   ` Robert Dewar
     [not found]     ` <matthew_heaney-ya023680002005981908570001@news.ni.net>
1998-05-21  0:00       ` John McCabe
1998-05-21  0:00         ` Matthew Heaney
1998-05-21  0:00         ` Robert Dewar
     [not found]       ` <01bd84c3$47215d60$440029a1@m00rq900>
1998-05-21  0:00         ` Robert Dewar
1998-05-21  0:00           ` Simon Pilgrim
1998-05-21  0:00             ` Matthew Heaney
1998-05-22  0:00               ` Robert I. Eachus
1998-05-22  0:00           ` Rod Chapman
1998-05-22  0:00             ` John McCabe
1998-05-22  0:00           ` Stuart Hutchesson
1998-05-22  0:00             ` Matthew Heaney [this message]
1998-05-23  0:00             ` Robert Dewar
1998-05-21  0:00         ` Matthew Heaney
1998-05-21  0:00         ` Robert Dewar
1998-05-21  0:00       ` Robert Dewar
1998-05-22  0:00         ` Robert I. Eachus
1998-05-23  0:00           ` Robert Dewar
replies disabled

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