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

查看:20
本文介绍了在 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).所以...

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. 我现在应该如何声明双精度真实?
  2. REAL(kind=dp)kind 是多余的吗?
  3. 在编译时是否需要任何特殊标志来使用 gfortranifort 调用双精度实数?
  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?

推荐答案

我个人现在写

use, intrinsic :: iso_fortran_env

其中包含int32real64等参数,含义很明显,可以这样使用:

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

请注意,标准不保证 kind=8 提供 8 字节的种类.kind 参数采用的值不是标准化的,并且因编译器而异.

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天全站免登陆