在Fortran中混淆双精度实数 [英] Confusing double precision real in Fortran
问题描述
DOUBLE PRECISION
,然后 REAL(kind = 8)
,然后 INTEGER,PARAMETER :: dp = kind(1.d0)
与 REAL(kind = dp)
- -Metcalf现在说 dp = kind(0.d0)
- 现在 float32 = selected_real_kind(6,37)
或 float64 = selected_real_kind(15,307)
。所以... - 我应该如何声明双精度实数?
- 是
kind
在REAL(kind = dp)
中有多余? - 是否有任何特殊标志在编译时需要使用
gfortran
或ifort
? - How should I be declaring double precision real now?
- Is
kind
redundant inREAL(kind=dp)
? - Are there any special flags needed at compile time to invoke double precision real with
gfortran
orifort
?
我现在写的是
use,intrinsic :: iso_fortran_env
其中包含 int32
,
real64
,它们具有明显的含义,可以像这样使用:
real(real64):: a_64_bit_real_scalar
请注意 kind = 8
不能保证按标准传递一个8字节的类型。类参数所采用的值不是标准化的,并且因编译器而异。
如果需要,可以编写诸如
use,intrinsic :: iso_fortran_env,dp => real64
...
real(dp):: a_64_bit_real_scalar
Have this burning question on my mind right now: What is the "accepted" way to declare double precision real in modern Fortran? In order from oldest to newest, the story seems to go like this: DOUBLE PRECISION
, then REAL(kind=8)
, then INTEGER, PARAMETER :: dp=kind(1.d0)
with REAL(kind=dp)
--Metcalf now says dp=kind(0.d0)
--and now float32=selected_real_kind(6,37)
or float64=selected_real_kind(15,307)
. So...
Personally I now write
use, intrinsic :: iso_fortran_env
which includes parameters such as int32
,real64
which have the obvious meanings, and can be used like this:
real(real64) :: a_64_bit_real_scalar
Note that kind=8
is not guaranteed, by the standard, to deliver an 8-byte kind. The values that kind parameters take are not standardised and do vary from compiler to compiler.
You could, if you want, write statements such as
use, intrinsic :: iso_fortran_env, dp=>real64
...
real(dp) :: a_64_bit_real_scalar
这篇关于在Fortran中混淆双精度实数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!