# Evaluation of trigonometric functions

## Evaluation of trigonometric functions

Hi all,

I haveupgraded a powerstationfortran project into an intel fortran project. Same routines, same code. Nothing but the compiler changes. Nevertheless, comparing the results of the two projects I have pumped into some differencies in the evaluation of trigonometric functions from the two compilers. The following code produces continuous values of the ACOS function when using powerstation whereas when using intel, it produces discrete evaluations:

THL=3.135642
THU=3.141124
R2=RAN(ISEED)
THRAN=ACOS(COS(THL)-R2*(COS(THL)-COS(THU)))

Can somebody tell me why this happens? How can I overcome thisissue? Is there a way to increase the accuracy of evaluation of trigonometric functions using intel compiler? It is seems as the compiler makes some roundings to the evaluated values and hence the discrete output.

Thanks

4 posts / 0 new
For more complete information about compiler optimizations, see our Optimization Notice.

The Microsoft compiler used the "X87" floating point instrctions which tended to give you "more than declared" precision. You may have liked this, but it was unpredictable and leads to confusion and complaints of inconsistency. Current Intel compilers use SSE instructions which are faster but keep values in the precision you declared. Since your values are right at the edge of the capability of single precision, it is not surprising that you believe that the Intel compiler is "rounding" and "discrete evaluations" when in fact it is giving you exactly what you asked for.

My advice would be to switch to double precision, including in the constants (add D0 at the end), as you seem to want the increase in precision. As an alternative you can try using the /arch:ia32 option (in Visual Studio, this is Fortran > Code Generation > Enable Enhanced Instruction Set > No enhanced instruction sets. This will slow down the code but will use X87 instructioins and you may get the phantom precision increase you want.

Retired 12/31/2016

Points to consider, in addition to what Steve Lionel wrote:

1. If you give specific evidence, with numerical results from both compilers, to support your claim of "discrete output" with IFort, you will be able to obtain more useful comments.

2. In any calculation involving calls to an RNG (Random Number Generator), differences in results can be attributed to

(i) differences in floating point hardware (X87 vs. SSE2, for example)

(ii) differences in generated code, which are also affected by compiler options in effect,

(iii) differences between the random number sequencess returned by the two RNGs.

If one is to avoid jumping to false conclusions, one needs to consider all these factors, as well as those that Steve Lionel wrote about. So far, we have completely ignored (iii) above.

Quoting mecej4Points to consider, in addition to what Steve Lionel wrote:

1. If you give specific evidence, with numerical results from both compilers, to support your claim of "discrete output" with IFort, you will be able to obtain more useful comments.

2. In any calculation involving calls to an RNG (Random Number Generator), differences in results can be attributed to

(i) differences in floating point hardware (X87 vs. SSE2, for example)

(ii) differences in generated code, which are also affected by compiler options in effect,

(iii) differences between the random number sequencess returned by the two RNGs.

If one is to avoid jumping to false conclusions, one needs to consider all these factors, as well as those that Steve Lionel wrote about. So far, we have completely ignored (iii) above.

Actually I was able to reproduce his discrete results, and Steve was dead on with his comment.
This had nothing to do with the particular random numbers, and everyting to do with precision.

To see it, I generated 10000 values and pulled them into Excel to plot them up.
At the top of the plot it is clear that there are discrete values the the generated values are clumping.

When the variables are changed to double precision, this clumping vanishes. I even increase to 64000 values, to get more at the top of the plot, to be sure that the clumping was gone for double precision.