Using scientific notation and underscore kind specifier at the same time for real literals in Fortran

二次信任 提交于 2019-11-27 19:33:59

问题


Using scientific notation for floating point literals is easy enough in Fortran:

1.5d-10

would mean a double precision (whatever that means under current Fortran compiler settings) floating point value that approximates 1.5*10^-15.

However, the fusion of the exponent notation and the floating point kind specifier is a bit of an issue. How would one declare this floating point literal when one wants it to have a type of C_DOUBLE?

I know that this is a bit of a nitpicking issue, but there can be circumstances when double precision will not be the same as C_DOUBLE.


回答1:


A real literal may be specified by any of the following forms:

  • 1.2
  • 1.2e0
  • 1.2d0
  • 1.2_kind
  • 1.2e0_kind

This final one is an example of using a kind specifier and an exponent. So, specific to the question: 1.5e-15_C_DOUBLE.

There certainly can be cases where 1.5d-15 is not the same as 1.5e-15_C_DOUBLE. The kind of a double precision and real(C_DOUBLE) are choices by the Fortran and companion C compilers respectively.

Compilers which allow single and double precision literal constants to be promoted to higher kinds by a compiler flag won't touch real(C_DOUBLE).



来源:https://stackoverflow.com/questions/49956241/using-scientific-notation-and-underscore-kind-specifier-at-the-same-time-for-rea

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!