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

about precision

keremusu1
Beginner
780 Views

Hello!

I need to set a variable "n" which is equal to 10E21. When I declare it as a "real" number, it appears to be 9.9999998E+021, and when I declare it as a "double precision" number, it appears to be 9.999999778196308E+021.

What should I do to make n=10E21 exactly.

0 Kudos
3 Replies
Steven_L_Intel1
Employee
780 Views
Double precision is good to only about 15 decimal digits. You could try quad precision (REAL(16)) which is good to 33 digits, but that will be a lot slower.

While integer values are exactly representable, assuming there are enough bits in the datatype, many decimal fractions are not.
0 Kudos
jimdempseyatthecove
Honored Contributor III
780 Views

Keremusu,

You might find this insightful

program

literals

real(8) :: a, b

a = 10E21

b = 10E21_8

write(*,*) a,b

end

program literals

Jim Dempsey

0 Kudos
Steven_L_Intel1
Employee
780 Views
I would also recommend the three-part series The Perils of Real Numbers.in the Newsletter thread.
0 Kudos
Reply