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
.
The E format code is used for scientific (exponential) notation. The value is rounded to d decimal positions and right justified into an external field that is w characters wide.
Fortran can use also scientific notation to represent real numbers. The sequence "En" attached to the end of a number, where n is an integer, means that the number is to be multiplied by 10n. Here are various ways of writing the number 12.345: 1.2345E1 , .
A double-precision exponent consists of the letter D , followed by an optional plus or minus sign, followed by an integer. A double-precision exponent denotes a power of 10. The value of a double-precision constant is the product of that power of 10 and the constant that precedes the D .
The KIND of a variable is an integer label which tells the compiler which of its supported kinds it should use. Beware that although it is common for the KIND parameter to be the same as the number of bytes stored in a variable of that KIND, it is not required by the Fortran standard.
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)
.
For real values which have no decimal part, there are additional available forms:
1.
1e0
1.e0
1d0
1.d0
1.e0_kind
1e0_kind
That is, the decimal part is optional, and if an exponent is given the decimal separator is also optional. Note however that 1
is an integer literal, while 1e0
and similar are real.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With