由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Computation版 - fortran90的超级怪问题
相关主题
谁给说说fortran的几个标准Question about overloading in fortran90
something strange in fortran90scientific computing还是Fortran90好阿
where to down a standard Fortran90 complier?fortran给数组赋初值一问
有没有free的Fortran Compiler阿?有关Fortran90的一个问题!
请问用mcc产生一个可执行文件后怎么运行?!!! How to adjust precision in CPLEX !!!
Re: matlab和fortran计算结果不一样该相信谁有推荐比较好的fortran 书吗?
Fortran error弱问:FORTRAN90调用子程序问题
Vi看来不是很适合编辑Fortran程序啊,不如emacs!偶也问一fortran问题
相关话题的讨论汇总
话题: precision话题: kind话题: program话题: your话题: r8
进入Computation版参与讨论
1 (共1页)
g******s
发帖数: 733
1
程序如下
PROGRAM MAIN
IMPLICIT NONE
real aa
aa=1023.0/2.0*1.0e-4
print*,aa
END PROGRAM
用f90 filename.f90 -o filename之后,filename出来的结果是0.051149997
用f77,把1023.0改成1021.0或1025.0,或者把*1.0e-4改成/1.0e4都对。
什么原因?先谢了!
f****r
发帖数: 27
2
It's called truncation error

【在 g******s 的大作中提到】
: 程序如下
: PROGRAM MAIN
: IMPLICIT NONE
: real aa
: aa=1023.0/2.0*1.0e-4
: print*,aa
: END PROGRAM
: 用f90 filename.f90 -o filename之后,filename出来的结果是0.051149997
: 用f77,把1023.0改成1021.0或1025.0,或者把*1.0e-4改成/1.0e4都对。
: 什么原因?先谢了!

g******s
发帖数: 733
3
i don't think it's truncation error. Even using double precision, the error
doesnot change. I believe sth is wrong in the codes or somewhere.

【在 f****r 的大作中提到】
: It's called truncation error
r****y
发帖数: 1437
4
For single precision, the machine precision is about 1e-7. Your result
is correct within machine precision.
For double precision, if you explicitly use 2.0D0, 1.0D-4. You will
get higher precision than single precision. If just 2.0, then your compiler
might convert it to 2.0000011111.
Different compilers can be a problem as well. Recently I have a code
working perfectly on SGI, Sun UNIX, Linux gnu compiler, but Linux PGI compiler
will give me a wrong answer.

【在 g******s 的大作中提到】
: i don't think it's truncation error. Even using double precision, the error
: doesnot change. I believe sth is wrong in the codes or somewhere.

g******s
发帖数: 733
5
Thanks a lot for your post, it's very helpful. I just found the problem you
said, and another very similar problem is coming for double double precision,
or real*16 (kind=16). Say I want to give pi a value 3.1415926536, the value
would not change if I explicitly use "D0". However, if I declare pi to be kind
=16, the value will change even when I explicitely used "D0".
Here is the code,
PROGRAM MAIN
IMPLICIT NONE
real(kind=16) pi
pi=3.1415926536d0
print*,pi
END
the value will change to 3.14159265

【在 r****y 的大作中提到】
: For single precision, the machine precision is about 1e-7. Your result
: is correct within machine precision.
: For double precision, if you explicitly use 2.0D0, 1.0D-4. You will
: get higher precision than single precision. If just 2.0, then your compiler
: might convert it to 2.0000011111.
: Different compilers can be a problem as well. Recently I have a code
: working perfectly on SGI, Sun UNIX, Linux gnu compiler, but Linux PGI compiler
: will give me a wrong answer.

r****y
发帖数: 1437
6
real (kind=16) is not double precision, it is quadraple precision. That's
why
your 3.14159***D0 failed.
if you really have to consider the precision proble up to kind=16, then most
time it means your code is not well written. There must be other way to do it
.
Usually, should not specify inside code, just write down
real a
**********
Then when you compile, use switch -r8, or -r16. This would be better than
your in-code declaration.
Seems you are such a rookie. Hehe.

,
kind

【在 g******s 的大作中提到】
: Thanks a lot for your post, it's very helpful. I just found the problem you
: said, and another very similar problem is coming for double double precision,
: or real*16 (kind=16). Say I want to give pi a value 3.1415926536, the value
: would not change if I explicitly use "D0". However, if I declare pi to be kind
: =16, the value will change even when I explicitely used "D0".
: Here is the code,
: PROGRAM MAIN
: IMPLICIT NONE
: real(kind=16) pi
: pi=3.1415926536d0

g******s
发帖数: 733
7
thanks a lot! But I don't know how to separate the compiling and link commands
. I use "f90 filename.f90 -o filename" which has put the compiling and link
together; or "f77 -c [-O4] filename.f" which doesn't recognize the switch "-r8
" or "-r16". What kind of compile and link commands shall I use if I want to
add the switch -r8 or -r16?

most
it

【在 r****y 的大作中提到】
: real (kind=16) is not double precision, it is quadraple precision. That's
: why
: your 3.14159***D0 failed.
: if you really have to consider the precision proble up to kind=16, then most
: time it means your code is not well written. There must be other way to do it
: .
: Usually, should not specify inside code, just write down
: real a
: **********
: Then when you compile, use switch -r8, or -r16. This would be better than

l******n
发帖数: 9344
8
write a makefile

commands
r8

【在 g******s 的大作中提到】
: thanks a lot! But I don't know how to separate the compiling and link commands
: . I use "f90 filename.f90 -o filename" which has put the compiling and link
: together; or "f77 -c [-O4] filename.f" which doesn't recognize the switch "-r8
: " or "-r16". What kind of compile and link commands shall I use if I want to
: add the switch -r8 or -r16?
:
: most
: it

1 (共1页)
进入Computation版参与讨论
相关主题
偶也问一fortran问题请问用mcc产生一个可执行文件后怎么运行?
[合集] 请教c下面大数祖问题Re: matlab和fortran计算结果不一样该相信谁
有人用过Matlab的Compiler吗?或者是否有什么工具能把Matlab程序转成C, C++?Fortran error
matlab改成C++,还用了号称史上最快的fftw,结果慢了一倍Vi看来不是很适合编辑Fortran程序啊,不如emacs!
谁给说说fortran的几个标准Question about overloading in fortran90
something strange in fortran90scientific computing还是Fortran90好阿
where to down a standard Fortran90 complier?fortran给数组赋初值一问
有没有free的Fortran Compiler阿?有关Fortran90的一个问题!
相关话题的讨论汇总
话题: precision话题: kind话题: program话题: your话题: r8