Quantcast
Channel: Intel® C++ Compiler
Viewing all articles
Browse latest Browse all 1616

#pragma float_control issue

$
0
0

Hello,

I am running into a problem I am at a loss to explain. I'm hoping somebody can point me to what I'm doing incorrectly.

I have a simple function and a main program in C, as follows:

1) Simple function in a file a.c:

#include <stdio.h>
#include <float.h>
#include <limits.h>
#include <math.h>

#ifdef __INTEL_COMPILER
#pragma float_control(precise,on,push)
#endif


static double
dstore(double x)
{
   return (x);
}

int myfunc()
{
   double x;
   x = 1.0;
   while (dstore(x / 2.0) != 0.0) {
      x /= 2.0;
   }
    (void)printf("  smallest positive number = %13.5le\n ", x);
   return 0;
}
#ifdef __INTEL_COMPILER
#pragma float_control(pop)
#endif

2) Main program in file b.c:

int myfunc();

int main()
{
   myfunc();
   return 0;
}

If I compile this on Win64 using the command

icl /O3 a.c b.c

then run the resulting executable I get

smallest positive number =  2.22507e-308

However, if I combine a.c and b.c into a single file and run it, I get

smallest positive number =  4.94066e-324

What I need to do is to set the function in the middle of a library that can be called by an application. The idea of the pragma is that the pragma will ensure that I get 4.94066e-324 no matter how the application is compiled. But what I'm finding out is that even with the pragma, if the function and the main program are in separate files it's as if the pragma isn't really working. It only works when called from within the same file.

Would somebody be kind enough to explain to me why this is happening and how I can correct this so that, in separate files, I still get the value 4.94066e-324 in my function?

Thanks.


Viewing all articles
Browse latest Browse all 1616

Trending Articles