Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/5/84; site unmvax.UUCP Path: utzoo!utcsrgv!garfield!philabs!cmcl2!lanl!unmvax!cliff From: cliff@unmvax.UUCP Newsgroups: net.unix-wizards,net.lang Subject: Re: Re: smart compilers Message-ID: <554@unmvax.UUCP> Date: Thu, 20-Dec-84 23:44:41 EST Article-I.D.: unmvax.554 Posted: Thu Dec 20 23:44:41 1984 Date-Received: Fri, 21-Dec-84 06:43:19 EST References: <6599@brl-tgr.ARPA> <979@opus.UUCP> <1146@ut-ngp.UUCP> <18397@lanl.ARPA> Organization: Univ. of New Mexico, Albuquerque Lines: 40 > > However, the IBM H Level FORTRAN Programmer's Guide does warn that code such > > as > > > > DO 100 I = 1 TO 10 > > IF (Y .GT. 0) X(I) = SQRT(Y) > > 100 CONTINUE > > > > (with X appropriately declared as an array of course) can cause an error > > because it tries to take the square root of a negative number. The optimizer > > compiles this as if it were > > > > TEMP = SQRT(Y) > > DO 100 I = 1 TO 10 > > IF (Y .GT. 0) X(I) = TEMP > > 100 CONTINUE > > This particular example should be optimized as > > IF ( Y.GT.0 ) TEMP=SQRT(Y) > DO 100 I = 1,10 !THERE ARE NO 'TO' DELIMITERS IN FORTRAN > X(I)=TEMP !FOLLOW INDENTATION STANDARDS PLEASE > 100 CONTINUE C Not quite. You will wind up setting X(I) to zero or the last value of TEMP C when Y is less than or equal to zero. How about something that would really C be correct, like: C IF (Y.LE.0) GO TO 100 TEMP = SQRT(Y) DO 100 I = 1, 10 X(I) = TEMP 100 CONTINUE C C The greatest derangement of the mind is to believe in something C because one wishes to be Louis Pasteur. C C --Cliff [Matthews] C {purdue, cmcl2, ihnp4}!lanl!unmvax!cliff C {csu-cs, pur-ee, convex, gatech, ucbvax}!unmvax!cliff C 4744 Trumbull S.E. - Albuquerque NM 87108 - (505) 265-9143