smart compilers
cliff at unmvax.UUCP
cliff at unmvax.UUCP
Fri Dec 21 14:44:41 AEST 1984
> > 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
More information about the Comp.unix.wizards
mailing list