Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.1 6/24/83; site astrovax.UUCP
Path: utzoo!watmath!clyde!burl!ulysses!mhuxl!ihnp4!astrovax!gam
From: gam@astrovax.UUCP (Gary Mamon)
Newsgroups: net.lang.f77
Subject: Another bug in UNIX 4.2 f77
Message-ID: <222@astrovax.UUCP>
Date: Fri, 24-Feb-84 15:20:02 EST
Article-I.D.: astrovax.222
Posted: Fri Feb 24 15:20:02 1984
Date-Received: Fri, 24-Feb-84 02:39:29 EST
Organization: Princeton Univ. Astrophysics
Lines: 36

If you thought you could get away using unoptimized f77 in UNIX 4.2, 
be careful! There are a few bugs. Here is a pretty serious one.
I am sorry that I am too ignorant in compilers to be able to suggest
a fix for it.

In double precision, if you raise an expression x to a variable power y, and
if the expression contains a power and at least another operation, then
Fortran "may" return y**y instead of x**y.

Here is a simple example:

	implicit real*8 (a-h,o-z)
c
111	continue
c
	print *,' enter x and y'
	read (5,*) x, y
c 
	z = (x**2.d0+1.d0)**(-y)
	anum = x**2.d0+1.d0
	power = -y
	z2 = anum**power
	print *,' x alph =',x,y
	print *,' anum power =',anum,power
	print *,' z z2 =',z,z2
c
	go to 111
	end

This program, compiled with no options, returns the wrong answer for z,
though z2 comes out correctly. Note that if the exponent is a constant 
(for example through a parameter statement), the answers are correct.

Gary Mamon				Princeton University, Astrophysics
{allegra,akgua,burl,cbosgd,decvax,ihnp4,kpno,princeton,vax135}!astrovax!gam