From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1164f8,42aaa616313a744c,start X-Google-Attributes: gid1164f8,public X-Google-Thread: 1094ba,42aaa616313a744c,start X-Google-Attributes: gid1094ba,public From: Michael.METCALF@cern.ch (Michael METCALF) Subject: Re: Fortran 90 merge statement Date: 1995/05/31 Message-ID: #1/1 X-Deja-AN: 103619014 sender: news@news.cern.ch (USENET News System) x-nntp-posting-host: misf59.cern.ch references: <3qhucj$kgg@gaia.ucs.orst.edu> organization: CERN - European Organization for Nuclear Research mime-version: 1.0 newsgroups: comp.lang.fortran,comp.sys.dec In article <3qhucj$kgg@gaia.ucs.orst.edu>, rodney@oce.orst.edu says... > >I have a question about the Fortran 90 merge statement. > >Consider the following Fortran 90 program: > > program merge_test > integer,parameter:: n=100 > real,dimension(-n:n):: x,y > integer:: i > real:: s > do i=-n,n > x(i) = real(i) > enddo > y = merge(1.0/x,0.0,x.ne.0.0) > s = sum(y) > write(*,*) 'sum = ',s > end > >It works fine on an RS/6000 and a CM5, but on a Dec Alpha, I get > > forrtl: error (73): floating divide by zero > >at merge statement. > >Does the standard specify how the merge is implemented? Is it legal to >evaluate the true and false statements _before_ checking the conditional as >the alpha compiler seems to be doing, or is the alpha compiler generating >incorrect code? > >-- > >-Rodney James (rodney@oce.orst.edu) > What the DEC compiler is doing is a legal interpretation of the standard. You could achieve the same effect, however, using the WHERE construct for masked assignment: where(x.ne.0.0) y = 1.0/x elsewhere y = 0.0 end where Mike Metcalf