Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.csd.uwm.edu!bionet!agate!saturn!helios!sla From: sla@helios (Steve Allen) Newsgroups: comp.lang.fortran Subject: operator precedence on FORTRAN 77 Summary: What does the standard say? Keywords: unary minus, exponenation Message-ID: <8980@saturn.ucsc.edu> Date: 2 Sep 89 04:18:57 GMT References: <3744@uwovax.uwo.ca> Sender: usenet@saturn.ucsc.edu Reply-To: sla@helios.ucsc.edu (Steve Allen) Distribution: na Organization: UC Observatories/Lick Observatory, Santa Cruz Lines: 31 Sender: 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