Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28945 Discussions

IFX power operator results changes when exponent is changed from constant to variable

NasarAli
New Contributor I
1,029 Views

IFORT does not have this issue.

IFX power operator result differs when exponent is:

1. integer constant

2. integer variable or real constant

 

10.02**4 = 10080.24121
(p=4) 10.02**p = 10080.24219

 

NasarAli_0-1714713633107.png

 

NasarAli_1-1714713647043.png

 

0 Kudos
1 Solution
NasarAli
New Contributor I
874 Views

For now, I changed the floating-point model to /fp:strict for IFX.

View solution in original post

0 Kudos
5 Replies
mecej4
Honored Contributor III
1,000 Views

Single-precision reals have seven significant decimal digits (23+1 bits in binary). You are looking at the ninth significant digit, and the apparent differences are artifacts of the output format conversion.

If the difference bothers you, use an appropriate format specification and print no more than seven significant digits.

0 Kudos
NasarAli
New Contributor I
995 Views

The double-precision real also have this issue. This code given here is just an example. The actual equations are very complex, and this issue causes a significant difference in final value.

0 Kudos
jimdempseyatthecove
Honored Contributor III
962 Views

>>The double-precision real also have this issue. 

Please note, 10.02**4 is a single precision expression. 10.02_8**4 is a double precision expression.

Also, 10.02**4.0, although you can see this as an integer power, the compiler may generate code as if this were non-integer power.

 

Note, if your code is sensitive to least significant bits in the expression, you can promote the expression to larger precision. If your variables are single precision then promote the components and expression to double precision (then convert back to single precision)

If your variables are double precision, promote to quad precision (real(16)).

 

Yes, this is a tradeoff between speed and precision.

 

Jim Dempsey

0 Kudos
JohnNichols
Valued Contributor III
916 Views

10080.240320160

Actual answer from HP35S and EXCEL, I would tend to believe them, first. 

0 Kudos
NasarAli
New Contributor I
875 Views

For now, I changed the floating-point model to /fp:strict for IFX.

0 Kudos
Reply