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

Calculation Problem with real*4 data

jcharod
Beginner
339 Views

I have tow identical programs one running on an Alpha withVMSand the other on a PC withWindows XP both are doing some calculations with real values and I am getting differences because the numbers used for the calculations are changing in the less significant digits after the decimal point for example

REAL X

X = 23.899997

If I print the value I will see 23.89999699603 on theWindows and 23.89999699328 on VMS(less significantdecimal digits) and if this value is used in several operations it is generating differences in the resultsbetween two versions for example 998.37238 in VMS against 998.3250 which is a significant difference for the kind of job I am doing.

Do you know a way to avoid having this kind of differences?

Thank you in advance

0 Kudos
4 Replies
jimdempseyatthecove
Honored Contributor III
339 Views

Migrating from platform to platform it is expected to see these types of differences.

When using decimal numbers whos fractions (in binary) cannot be exactly expressed in the precision available you are to accept "round-off errors". Your request is to ask for the same "round-off error" on different processor archetectures as well as different register level execution sequences. This is not a reasonable expectation.

Also, the significant digits of the precision of used for X (real*4), which is 8 digits, cannot be attained even if the decimal fractions are expressible in binary notation.

Consider converting the REAL*4 to REAL*8 for both the VMS and PC versions of the code. Produce a set of results data on the VMS system. Compare it to the REAL*4 results data on VMS, noting any differences that you approve or disapprove of. Then produce a set of results data on the PC. Using the data available, determine what is and what is not acceptible.

Note, back when you purchased the VMS system RAM was dear, now it is a pittance. Perhaps now is a good time to migrate to REAL*8. (or to make a blend of REAL*4 and REAL*8).

Jim Dempsey

0 Kudos
Steven_L_Intel1
Employee
339 Views
You may find that the Windows result is actually more accurate. By default, the IA-32 compiler will use double-precision for some intermediate computations of single-precision values. If you want it to be more consistent with Alpha, try adding the /Qx option that is appropriate for your CPU (such as /QxP for recent Pentium 4, or /QxT for Intel Core 2.

I'll also comment that single-precision is good to six decimal digits only. You are looking at differences in the 10th digit and if this is important, you should be using double precision.
0 Kudos
TimP
Honored Contributor III
339 Views
Compiler run-time libraries conform to IEEE standard for 32-bit reals if they produce 9 decimals. The standard specifically allows anything to happen beyond that, so there is no point in looking further unless you use double precision. Consider the value of SPACING(X).
0 Kudos
jcharod
Beginner
339 Views

I will try using /QxP option and check new results also Iwas planning to use a blend if REAL*4 and REAL*8 and see what happen

Now Ido knowthatsome differences need tobe accepted

Thank you

JCHAROD

0 Kudos
Reply