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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,7fd5a5da28dace78 X-Google-Attributes: gid103376,public From: matthew_heaney@acm.org (Matthew Heaney) Subject: Re: Renaming Fixed Point Mutiplicative operator in Ada 95 Date: 1998/05/22 Message-ID: #1/1 X-Deja-AN: 355574841 Content-Transfer-Encoding: 8bit References: <3561F32B.2F0B@innotts.co.uk> <01bd84c3$47215d60$440029a1@m00rq900> <01bd8589$5fa05a00$440029a1@m00rq900> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Organization: Network Intensive Newsgroups: comp.lang.ada Date: 1998-05-22T00:00:00+00:00 List-Id: In article <01bd8589$5fa05a00$440029a1@m00rq900>, "Stuart Hutchesson" 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?)