Make constants explicitly double precision, otherwise they are unintentionally treated as single precision by Fortran 90 #1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When making an assignment statement such as the below, one might think that
pi
is treated as a double precision float:However, Fortran 90, unlike Fortran 77, will treat
pi
as a single precision float, rather than a double. This is a known (and rather counterintuitive) behavior of Fortran 90. Below is a minimum working example of this behavior in Fortran:The output of the above program when I run it (compiling with
gfortran
, as part of GCC 11.1.0) is:Note the difference in results.
Now, consider the following C program:
The output of the above is:
Notice how
foo^3
matches the Fortran results, andbar^3
matches the Fortran results up to 6 decimal places. This makes sense given single precision (a rule of thumb for single precision is 7 decimal places when using scientific notation). In other words, these results demonstrate that Fortran treatsbar
as a single precision float, because we did not append the_dp
to the end of it.See also the following sources online:
In this pull request, I have appended
_dp
to constants used by this code, in places where it appears that the intention was to use double precision. Of course, this subtly changes the numerical results. I have tested withtest1.in
and it does appear to work.Pinging contributors: @garrelt @abken601