在Fortran中混淆双精度实数 [英] Confusing double precision real in Fortran

查看:810
本文介绍了在Fortran中混淆双精度实数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在我的脑海里有这个灼热的问题:在现代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)。所以...


  1. 我应该如何声明双精度实数?

  2. kind REAL(kind = dp)中有多余?

  3. 是否有任何特殊标志在编译时需要使用 gfortran ifort


    1. 解决方案

      我现在写的是

        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...

      1. How should I be declaring double precision real now?
      2. Is kind redundant in REAL(kind=dp)?
      3. Are there any special flags needed at compile time to invoke double precision real with gfortran or ifort?

      解决方案

      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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆