1

I have a scenario where i declare a variable real*8 and read a value

0.1234123412341234

which is stored in a file.

When i try to read it on Linux to a variable and display the value, it prints

0.12341234123412

whereas when i run the same code for AIX it prints the value

0.12341234123412370

Why does both the platform print different values for the same code? Is there any possibility to overcome this without using format specifier?

P.S

AIX compiler is xlf

Linux compiler is ifort

4

2 回答 2

2

我假设您使用的是列表导向的 IO write (X, *),. 虽然这种类型的 IO 很方便,但标准并未完全指定输出。如果您希望您的输出在编译器和平台之间非常相似,您应该使用一种格式。(由于使用了有限精度算术,您的结果可能仍然存在细微差异。)

于 2013-10-07T13:23:02.490 回答
0

你不应该使用REAL*8声明双变量,你应该使用

INTEGER, PARAMETER :: prec = SELECTED_REAL_KIND(15,307)
REAL(prec) :: variable

指定可移植的双精度变量(有关详细信息,请参见此处)。

无论如何,您遇到的问题与精度有关。双精度变量在出错之前可以达到 15 位,这似乎是两种编译器的情况。事实上,我认为这些确实是相同的数字,因为它们非常接近(大约 3E-12 的百分比差异)。

于 2013-10-07T13:23:17.703 回答