sla@helios (Steve Allen) (09/02/89)
Which takes precedence, a unary minus, or an exponentiation? This question recently came up when one of our users ran a code which should have had more parentheses. The example is below. My own impression is that the Sun interpretation is the only one that makes sense, but I don't know what the FORTRAN-77 standard requires. Is there a correct interpretation? double precision func1, func2, func3, func4 func1 = 10.D0** -(3.D0)/2.D0 func2 = 10.D0**(-(3.D0)/2.D0) func3 = 10.D0** -3.D0 /2.D0 func4 = 10.D0** - 3.D0 /2.D0 write(*,*) func1, func2 write(*,*) func3, func4 end Sun Fortran 1.x (x is either 0 or 1, I'm not sure) on a Sun4 with SunOs 4.0.y (y is either 0 or 1, ditto) gives 5.0000000000000D-04 3.1622776601684D-02 5.0000000000000D-04 5.0000000000000D-04 VAX FORTRAN V4.7-271 on a MicroVax II with VMS V4.7 gives 3.1622776601683793E-02 3.1622776601683793E-02 3.1622776601683793E-02 3.1622776601683793E-02 Mips Computer Systems 1.31 Fortran on a SGI 4d/220 running IRIX V3.1F gives 3.1622776601683790E-02 3.1622776601683790E-02 3.1622776601683790E-02 3.1622776601683790E-02 Steve Allen sla@helios.ucsc.edu sla@portal.bitnet
brainerd@unmvax.unm.edu (Walt Brainerd) (09/03/89)
In article <8980@saturn.ucsc.edu>, sla@helios (Steve Allen) writes: > Which takes precedence, a unary minus, or an exponentiation? This question The standard (p 6-2, l. 45): "the exponentiation operator has precedence over the negation operator", but I don't think this is the relevant fact. > recently came up when one of our users ran a code which should have had more > parentheses. The example is below. My own impression is that the > Sun interpretation is the only one that makes sense, but I don't know > what the FORTRAN-77 standard requires. Is there a correct interpretation? > No, see below. > double precision func1, func2, func3, func4 > func1 = 10.D0** -(3.D0)/2.D0 > func2 = 10.D0**(-(3.D0)/2.D0) > func3 = 10.D0** -3.D0 /2.D0 > func4 = 10.D0** - 3.D0 /2.D0 > write(*,*) func1, func2 > write(*,*) func3, func4 > end > The expressions in all but func2 are illegal in F77 and still will be illegal in the propsed F8x. Therefore, all of the implementations cited have treated this as an extension and are free to give any interpretation they want. The only relevant question is whether one or the other interpretation makes better sense, is more in conformance with mathematical usage, or is a more logical extension of the exiting rules of Fortran. func3 and func4 must be equivalent because blanks are insignificant in Fortran 77 source. func1 also must be equivalent because putting parens around a constant should have no effect. The two interpretations cited correspond to placing parens as follows (the D is also irrelevant). (10. ** -3.) / 2. 10. ** (-3. / 2.) The first seems more reasonable because ** has higher precedence than /, but one catch is that 10. ** -3 is still illegal, so must be interpreted as if it were 10. ** (-3.). I guess I would agree that the Sun interpretation (the one on the left) is what I would expect, but this is just OPINION. -- Walt Brainerd Unicomp, Inc. brainerd@unmvax.cs.unm.edu 2002 Quail Run Dr. NE Albuquerque, NM 87122 505/275-0800
hybl@mbph.UUCP (Albert Hybl Dept of Biophysics SM) (09/06/89)
In message <8980@saturn.ucsc.edu> from sla@helios.ucsc.edu, Steve Allen posted a short validation program and asked what the correct interpretation should be: > double precision func1, func2, func3, func4 > func1 = 10.D0** -(3.D0)/2.D0 > func2 = 10.D0**(-(3.D0)/2.D0) > func3 = 10.D0** -3.D0 /2.D0 > func4 = 10.D0** - 3.D0 /2.D0 > write(*,*) func1, func2 > write(*,*) func3, func4 > end The gentleman from the University of New Mexico at Albuquerque speaking in a firm, judicial voice provided the interpretation in message <320@unmvax.unm.edu>: }The expressions in all but func2 are illegal in F77 and still will be }illegal in the proposed F8x. He then explains why X3.9-1978 FORTRAN fails to provide users with a portable standard--i.e., the suicide sentence! } Therefore, all of the implementations }cited have treated this as an extension and are free to give any }interpretation they want. IMPLEMENTORS SHOULD NOT BE FREE TO GIVE ANY INTERPRETATION THEY WANT! THEY SHOULD REPORT AN ERROR AND/OR SUBMIT THE PROBLEM FOR ADJUDICATION! How can a validation suite be useful to either the user or the implementor when ALL of the following disparate answers are legal because they are standard conforming or allowed because they are NOT standard conforming? From and AT&T 3B1 using SVS fortran MC68000 FORTRAN 77 Compiler V2.2 21-May-84 2. *********** func1 = 10.D0** -( <=== 3.D0)/2.D0 ***** Error number 50 in line 2 of file allen.for ***** ***** Illegal symbols in an expression ***** 4. *********** func3 = 10.D0** -3 <=== .D0 /2.D0 ***** Error number 50 in line 4 of file allen.for ***** ***** Illegal symbols in an expression ***** 5. *********** func4 = 10.D0** - <=== 3.D0 /2.D0 ***** Error number 50 in line 5 of file allen.for ***** ***** Illegal symbols in an expression ***** 3 errors. 8 lines. File allen.for From an IBM-PC/AT using the IBM Professional FORTRAN Compiler (V1.21) by Ryan-McFarland Corp 2 func1 = 10.D0** -(3.D0)/2.D0 ? 1 ** ERROR ** : UNRECOGNIZABLE SYNTAX AT THIS POINT 4 func3 = 10.D0** -3.D0 /2.D0 ? 1 ** ERROR ** : UNRECOGNIZABLE SYNTAX AT THIS POINT 5 func4 = 10.D0** - 3.D0 /2.D0 ? 1 ** ERROR ** : UNRECOGNIZABLE SYNTAX AT THIS POINT From an AT&T 3B2/400 using Fortran 77 XLA+ 5.000000000E-004 3.162277660E-002 5.000000000E-004 5.000000000E-004 >Sun Fortran 1.x (x is either 0 or 1, I'm not sure) >on a Sun4 with SunOs 4.0.y (y is either 0 or 1, ditto) gives > 5.0000000000000D-04 3.1622776601684D-02 > 5.0000000000000D-04 5.0000000000000D-04 > >VAX FORTRAN V4.7-271 on a MicroVax II with VMS V4.7 gives > 3.1622776601683793E-02 3.1622776601683793E-02 > 3.1622776601683793E-02 3.1622776601683793E-02 > >Mips Computer Systems 1.31 Fortran on a SGI 4d/220 > running IRIX V3.1F gives > 3.1622776601683790E-02 3.1622776601683790E-02 > 3.1622776601683790E-02 3.1622776601683790E-02 > Three cheers for AT&T/SVS and IBM/RM. A BIG BOO for the suicide idea! ---------------------------------------------------------------------- Albert Hybl, PhD. Office UUCP: uunet!mimsy!mbph!hybl Department of Biophysics Home UUCP: uunet!mimsy!mbph!hybl!ah University of Maryland CoSy: ahybl School of Medicine Baltimore, MD 21201 Phone: (301) 328-7940 (Office) ----------------------------------------------------------------------
brainerd@unmvax.unm.edu (Walt Brainerd) (09/06/89)
In article <606@mbph.UUCP>, hybl@mbph.UUCP (Albert Hybl Dept of Biophysics SM) writes: > > The gentleman from the University of New Mexico at Albuquerque ^^^^^^^^^ > speaking in a firm, judicial voice provided the interpretation Do I detect a hint of sarcasm? I'm not with UNM as the signature line indicates; they let me use their mail system, but I don't want them embarassed by what I say. > IMPLEMENTORS SHOULD NOT BE FREE TO GIVE ANY INTERPRETATION THEY WANT! > THEY SHOULD REPORT AN ERROR AND/OR SUBMIT THE PROBLEM FOR ADJUDICATION! In Fortran 8x, implementors will be required to report nonstandard syntax (as in the examples), but we have had this whole discussion before. -- Walt Brainerd Unicomp, Inc. brainerd@unmvax.cs.unm.edu 2002 Quail Run Dr. NE Albuquerque, NM 87122 505/275-0800
hybl@mbph.UUCP (Albert Hybl Dept of Biophysics SM) (09/08/89)
In posting <360@unmvax.unm.edu> from brainerd@unmvax.unm.edu, Walt Brainerd writes: >In article <606@mbph.UUCP>, hybl@mbph.UUCP (Albert Hybl >Dept of Biophysics SM) writes: >> The gentleman from the University of New Mexico at Albuquerque > ^^^^^^^^^ >Do I detect a hint of sarcasm? Gee, I thought my words were as easy to interpret as F77-extended. >I'm not with UNM as the signature line indicates; ... Too bad, you would be an asset to UNM. I thought you were with the Computer Science Department. Although, if that were the case, it would be strange for you to be interested in Fortran. >> IMPLEMENTORS SHOULD NOT BE FREE TO GIVE ANY INTERPRETATION THEY WANT! >In Fortran 8x, implementors will be required to report nonstandard >syntax (as in the examples), . . . I have used several mainframe systems that already contain this feature. In every case the system default has the option turned off--the user has to explicitly turn it on to derive benefit from it. I concluded that it wasn't worth dinosaur DOo-DOo! I do not see any reason for the implementor to second guess what the programmer intended nor should the programmer try to second guess what the implementor extended. I think extensions to F88 could be ok--but only if they are official extensions arrived at by a sensible review process and published in an appropriate journal. A language standard should not contain the 'if it is standard, it is portable; if it is non-standard, anything is allowable' nonsense! ^^^^^^^^ ---------------------------------------------------------------------- Albert Hybl, PhD. Office UUCP: uunet!mimsy!mbph!hybl Department of Biophysics Home UUCP: uunet!mimsy!mbph!hybl!ah University of Maryland CoSy: ahybl School of Medicine Baltimore, MD 21201 Phone: (301) 328-7940 (Office) ----------------------------------------------------------------------