🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.fortran
Article #4621

Compiler bug (was: simple calculation, varying results)

#4621
From: Viggo L. Norum
Date: Mon, 07 Aug 1995 07:47
37 lines
2055 bytes
On 20 Jul 1995 I posted a problem to comp.lang.fortran under the title
"simple calculation, varying results".  This message is ment to inform
you of the solution of the problem and thereby help you to avoid a pitfall.

I got several answers to my last message, but none of them solved the 
problem.  I made a simpler test code (see below) than the one posted to 
c.l.f, and mailed it to NAG.  After ten days, NAG responded:

> The problem is with the HP C compiler math library powf function,
> which was used by NAGWare f90 for the ** operator.  This gives random
> spurious wrong results.
>
> We have recently fixed this bug and I will prepare the latest version
> of the compiler for you.  We now use pow rather than powf.
[...]

My conclusion to NAG's answer:
If you are using C or NAG's f90 on a HP and don't want your calculations 
to give "random spurious wrong results", then you should test your 
compiler/C-math-library for this bug.  You may use the following fortran 
code for testing:

      PROGRAM test
      REAL s
      s=.7
      WRITE(*,*) sqrt( s  **1.5d0- s**1.7d0)
      WRITE(*,*) sqrt( s  **1.5e0- s**1.7e0)
      WRITE(*,*) sqrt( s  **1.5  - s**1.7  )
      WRITE(*,*) sqrt(.7  **1.5  -.7**1.7  )
      WRITE(*,*) sqrt(.7d0**1.5  -.7**1.7d0)
      END

The correct result is 0.2008.. for all the writes.  The answers I got 
(without the bug fix) varied between 1.119 and 0.2008.  The results are 
OK when using pow in stead of powf (NAG's bug fix).

Viggo L Norum
Technical Details
Message-ID: <404geb$55s@due.unit.no>
Path: arc1-ca.pugleaf.net!due.unit.no!usenet

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!due.unit.no!usenet
From: "Viggo L. Norum" <vnorum@marina.unit.no>
Newsgroups: comp.lang.fortran,comp.lang.c
Subject: Compiler bug (was: simple calculation, varying results)
Date: 7 Aug 1995 07:47:23 GMT
Organization: Institute of Marine Machinery, NTH
Message-ID: <404geb$55s@due.unit.no>
NNTP-Posting-Host: aqua2.marina.unit.no
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
X-Mailer: Mozilla 1.1N (X11; I; HP-UX A.09.05 9000/712)
X-URL: news:comp.lang.fortran