作者sjgau (sjgau)
看板Programming
标题Re: [问题] 关於fotran数值运算的误差问题
时间Tue Nov 7 09:28:13 2006
program test
real(kind=8) a, b, c
a=0.100000000001*1D300
a= 0.100000000001D300
b=0.100000000000*1D300
b= 0.100000000000D300
c= a - b
write(*,*) a-b, c
end
! 1.000000283239953E+288 1.000000283239953E+288
! Press any key to continue
上面,我只改动 a= , b=
就可以得到 原po 想要的结果
※ 引述《[email protected] (人生=无尽的任务)》之铭言:
: 我不懂 fortran
: 但可能有两种原因只显示 0.00000
: 1.fortran 储存 real 只用不到 8 bytes(应该不太可能?)
: 2.write要设定显示科学记号表示法
: ※ 引述《[email protected] (sjgau)》之铭言:
: > #include "stdafx.h"
: > #include <math.h>
: > int main(int argc, char* argv[])
: > {
: > double a, b, c;
: > printf("\nsizeof(c)= %d bytes\n", sizeof(c));
: > a=0.100000000001e300;
: > b=0.100000000000e300;
: > c= a - b;
: > printf("\nc= %25.22le\n", c);
: > return 0;
: > }
: > /*
: > sizeof(c)= 8 bytes
: > c= 1.0000002832399531000000e+288
: > Press any key to continue
: > */
: > 手边暂时 没有 fortran 的 compiler
: > 先使用 对等的 C 帮你看看
: > 你 看看那个 c 的答案 是否为你 所要的,
: > 然後,私下用 e-mail 讨论吧
: > [email protected]
: > 这种简单的问题讨论,
: > 是会被 公干的
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 220.228.165.65