Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
29285 Discussions

Question about simple algebra error in intel fortran 90

qlsn5
Beginner
345 Views

I have computed the following :

-------------------------------

real(kind=8) :: x, y, z

x = 1.0_8
y = 0.9747_8
z = x - y

---------------------------------

but the result is "2.529999999999999E-002", not "2.53e-002".

Why this happen?

0 Kudos
1 Reply
TimP
Honored Contributor III
345 Views

As the 53-bit binary precision of real(8) is equivalent to 15 to 17 decimal digits precision, and you lose a few bits by subtraction of similar magnitute numbers, that's all the accuracy you can expect.  If you would specify formatting with rounding to 15 or fewer digits, you should get what you expected.

0 Kudos
Reply