[Bug fortran/40070] New: Some math expressions containing exponents fail on a Windows 64 build

2009-05-08 Thread jonathan dot d dot wetherbee at saic dot com
Some equations using exponents on Windows XP Professional 64-bit evaluate
incorrectly, but can be computed correctly by splitting up the equation into
multiple statements.

I apologize in advance if this turns out to be just a MinGW bug, but thought
I'd start with gcc first.

I am using MinGW GFortran with the following built-in specs.
Target: x86_64-pc-mingw32
Configured with: ../gcc/configure --target=x86_64-pc-mingw32
--prefix=/c/buildbot/vista64-mingw32/mingw-x86/build/root
--with-sysroot=/c/buildbot/vista64-mingw32/mingw-x86/build/root
--disable-multilib --enable-languages=all,obj-c++
Thread model: win32
gcc version 4.4.0 20090110 (experimental) (GCC)


Here is some sample code that demonstrates the problem:
myfunc.f

  Subroutine myfunc(a,b,c,d,e,res1,res2)

  Real a,b,c,d,e
  Parameter (g = 273.15)


  res1 = a*(b/a)**((c-d-g)/(e-d))

  res2 = (b/a)**((c-d-g)/(e-d))
  res2 = res2 * a

  Return
  End


  Subroutine myfunc2(a,b,c,d,res1,res2)

  Real a,b,c,d,res1,res2

  res1 = a*(b/c)**d
  res2 = (b/c)**d
  res2 = a * res2

  Return
  End

  Subroutine myfunc3(a,b,c,d,e,f,g,h,i,res1,res2)

  Real a,b,c,d,e,f,g,h,i,res1,res2

  res1 = a*((b/(b+c*(d-e)))**((f*g)/(h*i)))*100.
  res2 = ((b/(b+c*(d-e)))**((f*g)/(h*i)))*100.
  res2 = a*res2

  Return
  End




main.c
--

#include stdio.h


extern void myfunc(float *a, float *b, float *c, float *d, float *e, float
*res1, float *res2); 
extern void myfunc2(float *a, float *b, float *c, float *d, float *res1, float
*res2); 
extern void myfunc3(float *a, float *b, float *c, float *d, float *e, float *f,
float *g, float *h, float *i, float *res1, float *res2); 

int main( int argc, char *argv[] )
{
float a,b,c,d,e,f,g,h,i,res1,res2;

a=1000.0;
b=850.0;
c=143.204;
d=30.5280;
e=8.2351;
res1 = 0;
res2 = 0;

myfunc(a,b,c,d,e,res1,res2);

printf(Function 1:\n\nresult 1: %f\nresult 2:
%f\n\n,res1,res2);


a=103780.0;
b=253.13005;
c=231.676270;
d=-16.904803;

myfunc2(a,b,c,d,res1,res2);

printf(Function 2:\n\nresult 1: %f\nresult 2:
%f\n\n,res1,res2);


a=1513.25;
b=238.149994;
c=-16.500040;
d=3.2;
e=0;
f=9.806650;
g=20.964399;
h=7614.320313;
i=-0.1065;

myfunc3(a,b,c,d,e,f,g,h,i,res1,res2);

printf(Function 3:\n\nresult 1: %f\nresult 2:
%f\n\n,res1,res2);

return 0;

}





Compiled with the following options:
-fno-uncerscoring
-fno-range-check
-W
-std=f95


-- 
   Summary: Some math expressions containing exponents fail on a
Windows 64 build
   Product: gcc
   Version: 4.4.0
Status: UNCONFIRMED
  Severity: blocker
  Priority: P3
 Component: fortran
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: jonathan dot d dot wetherbee at saic dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40070



[Bug fortran/40070] Some math expressions containing exponents fail on a Windows 64 build

2009-05-08 Thread jonathan dot d dot wetherbee at saic dot com


--- Comment #2 from jonathan dot d dot wetherbee at saic dot com  
2009-05-08 15:03 ---
I used C code to call the function because the fortran code is being compiled
into a C based application.

When I run the sample main function, the values are obviously different.

Function 1:
result 1: 0.000
result 2: 310.403625

Function 2:
result 1: 0.000
result 2: 23223.025391

Function 3:
result 1: -4171845731254704300.
result 2: 142007.828125


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40070



[Bug fortran/40070] Some math expressions containing exponents fail on a Windows 64 build

2009-05-08 Thread jonathan dot d dot wetherbee at saic dot com


--- Comment #4 from jonathan dot d dot wetherbee at saic dot com  
2009-05-08 15:27 ---
When I run Dominique's main function written in fortran, I get:

res1res2   res1-res2
 6.09E-24   310.40363  -310.40363
 8.92E-23   23223.025  -23223.025
-4.01E-06   142007.59  -142007.59

Oddly enough, just about every other line in this 20,000 line fortran code
works fine.  It is starting to look like it might just be my build of gcc.

I'm running it on an Intel Xeon E5450.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40070



[Bug fortran/40070] Some math expressions containing exponents fail on a Windows 64 build

2009-05-08 Thread jonathan dot d dot wetherbee at saic dot com


--- Comment #7 from jonathan dot d dot wetherbee at saic dot com  
2009-05-08 15:40 ---
Checked the size of a float with sizeof(float) and got 4 bytes.  How can I
check the size of REAL in fortran?

When I try the USE ISO_C_BINDING I get the same result.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40070



[Bug fortran/40070] Some math expressions containing exponents fail on a Windows 64 build

2009-05-08 Thread jonathan dot d dot wetherbee at saic dot com


--- Comment #10 from jonathan dot d dot wetherbee at saic dot com  
2009-05-08 15:51 ---
When I run the fortran code: print *, precision(1.e0), digits(1.e0)
I get: 6,24


*.original file yields:

myfunc (real(kind=4)  a, real(kind=4)  b, real(kind=4)  c, real(kind=4)  d,
real(kind=4)  e, real(kind=4)  res1, real(kind=4)  res2)
{
  {
real(kind=4) D.1529;

D.1529 = ((*b / *a));
*res1 = *a * __builtin_powf (D.1529, (*c - *d) -
2.73149993896484375e+2)) / ((*e - *d);
  }
  {
real(kind=4) D.1530;

D.1530 = ((*b / *a));
*res2 = __builtin_powf (D.1530, (*c - *d) - 2.73149993896484375e+2)) /
((*e - *d);
  }
  *res2 = *res2 * *a;
  goto __return_myfunc;
  __return_myfunc:;
}


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40070