- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
My question has more to do with the VisualStudio C++ compiler than with Fortran itself, but I hope someone can help.
I am looking into an issue that has to do with getting different results from a piece of code that has been compiled as a 32- and 64-bitexecutable using VisualStudio 2005.
Here's the source code:
#include
double a, b, c;
a = -73.66266;
b = 0.017453292519943295;
c = sin(a * b);
printf("sin(c) = %0.17f\n", c);
To run this code just create a console project within VisualStudio and configure it for 32 and 64-bit executables. Use default compiler settings. I performed this test on anIntel machine running Win Server 2008 64-bit, with optimization disabled (I believe the same behavior can be reproduced using Win XP 64-bit).These two executables produce slightly differentresults:
Output from 32-bit code = -0.95962217600146471
Output from 64-bit code = -0.95962217600146482
Converting the above code to Fortran(IVF 10.0)and running it on the same machine, the output produced by the 32-bit version is identical to that produced by the 64-bit version. It should be mentioned, however, that the Fortran output is different from the C++, which is understandable taking into account we are dealing with two different compilers.
My question is if anyone has run into this situation, and if there's a way of forcing the C++ compiler to produce floating point results that are identical for both 32- and 64-bit executables? I have played with the compiler settings (/fp:precise, /fp:strict, and /fp:fast), but it does not appear to affect the results.
Thanks
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Microsoft compilers default to /fp:precise, which, like Intel C++ but unlike Intel Fortran, promotes float expressions to double evaluation, even for SSE2. Microsoft /fp:fast is analogous to Intel /fp:source (including observance of parentheses), if you disable vectorization on the Intel compilers. There is no way, other than parentheses, to enforce left-to-right evaluation in Microsoft C or Intel Fortran.
Your C constants are doubles; do you take care to specify your Fortran constants in kind=8 ?
![](/skins/images/872293744008A34B36F8ABF94A46CC66/responsive_peak/images/icon_anonymous_message.png)
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page