实际变量的精度 [英] precision of real variable
本文介绍了实际变量的精度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在FORTRAN 77中有以下代码:
I have the following code in FORTRAN 77:
REAL*8 :: dm
dm=1.-1.E-12
write(6,*) 'dm: ', dm
我得到: dm:1
可以吗?我想得到 dm = 0.999999999999
推荐答案
评论,你需要指定常量的精度。此外, real * 8
已过时。 (它总是一个扩展吗?)这是一种现代的写法,使用ISO Fortran Environment获取64位实型,并在声明和常量中使用该类型。
As stated in a comment, you need to specify the precision of the constants. Also, real*8
is obsolete. (Was it always an extension?) Here is a modern way to write this, using the ISO Fortran Environment to obtain a 64-bit real type and using that type both in the declaration and in the constants.
use ISO_FORTRAN_ENV
real (real64) :: dm
dm = 1.0_real64 - 1.0E-12_real64
For more info, see What does `real*8` mean?
这篇关于实际变量的精度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文