Thread View: comp.lang.fortran
1 messages
1 total messages
Started by Viggo L. Norum
Mon, 07 Aug 1995 07:47
Compiler bug (was: simple calculation, varying results)
Author: Viggo L. Norum
Date: Mon, 07 Aug 1995 07:47
Date: Mon, 07 Aug 1995 07:47
37 lines
2055 bytes
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
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads