Fortran 编译器 4 与 11
我正在将应用程序从 Fortran 旧版本 (4.0) 移植到新版本 (11.0)。在移植时,我遇到了一些有关 real*4 变量的问题:
real*4 a,b,c
a=0.9876875
b=0.6754345
c=a*b
旧编译器 0.667118
中 c
的值,这是正确的值。但是使用新的编译器,我得到的输出(c 变量)有一些微小的变化,例如 0.667120
。尽管变化很小,但我在其他计算中使用了这些值。所以整体的输出有很大的差异。如何克服这个问题?
I am porting an application from fortran older version (4.0) to new version (11.0). While porting I am facing some problems with real*4 variables:
real*4 a,b,c
a=0.9876875
b=0.6754345
c=a*b
value for c
in old compiler 0.667118
, which is correct value. But with new compiler I am getting a small variation from the output(c variable) like 0.667120
. Though it is a small variation, I am using these values in some other calculation. So the overall output has a huge difference. How to overcome this issue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我假设您正在从 Microsoft Fortran Powerstation 4 转到 Intel Visual Fortran 11.xx ?
无论如何,试试这个:
它给出:
我不会解释 selected_real_kind ,不是因为我不希望,而是因为帮助可能会做得更好。但是,如果这里有不清楚的地方,请务必询问。
ps real*4 或任何类型的 real 的表示形式取决于处理器和编译器,这就是您获得不同结果的原因之一。
You are, I'm assuming, going from Microsoft Fortran Powerstation 4 to Intel Visual Fortran 11.xx ?
Anyways, try this:
which gives out:
I will not explain selected_real_kind, not because I do not wish, but because the help will probably do it much better. But, do ask if something in here is not clear.
p.s. The representation of real*4, or any type of real is processor dependent, and compiler dependent and that is one of the reasons why you're getting different results.
此处讨论英特尔 Visual Fortran 编译器版本 11 的更改:
http://software.intel.com/en-us/forums/intel-visual-fortran-compiler-for-windows/topic/68587/
结果是旧版本的Fortran 编译器在执行操作之前会隐式地将单精度值提升为双精度。版本 11 中的默认行为是以单精度执行运算。有编译器选项 (
/arch:ia32
) 可以在新编译器中启用旧行为。Discussion of changes in Intel visual Fortran compiler version 11 here:
http://software.intel.com/en-us/forums/intel-visual-fortran-compiler-for-windows/topic/68587/
The upshot is that older versions of the Fortran compiler would implicitly promote single-precision values to double-precision before performing an operation. The default behavior in version 11 is to perform the operation with single-precision. There are compiler options (
/arch:ia32
) to enable the old behavior in the new compiler.我假设您使用的是英特尔。尝试编译而不优化..
I assume you are using Intel. Try to compile without optimization..