Fortran Modern variable precision and integer multipliers

AI Thread Summary
The discussion centers on the compatibility of older Fortran syntax, particularly the use of real*8, with modern Fortran environments. The primary concern is whether real*8 maintains full double precision in calculations, especially when mixed with implicit declarations and arithmetic operations. It is confirmed that double precision typically provides around 15 digits of precision, and operations involving different data types will promote the lower precision type to the higher one. The compatibility of real*8 with newer compilers is questioned, and it is suggested that users can run tests to compare results between real*8 and the KIND parameter for accuracy. Additionally, the simpler definition of pi using implicit declarations is examined, with no significant loss of precision noted, provided the calculations remain within the bounds of double precision.
avikarto
Messages
56
Reaction score
9
I learned Fortran from ancient people who disregard modern standards. As such, my code consists mainly of that older syntax. I am wondering how well this meshes with current Fortran environments, specifically regarding double precision calculations. This comes up mainly because I have been told that real*8 and similar declarations should be abandoned in favor of KIND.

For example, in the following code section
Fortran:
real*8 x,y,z
x=12.3456
y=2*x
z=2.d0*x

will y maintain full double precision, or will a statement like z be required?

Similarly, if the fractional nature of the initial variable is defined only implicitly,
Fortran:
real*8 pi,y,z
pi=4*atan(1)
y=2*pi
z=2.d0*pi

does this change the nature of y or z?

Or, for that matter, does pi maintain an appropriate value here instead of being declared as pi=4.d0*atan(1.d0)?

Thanks.
 
Technology news on Phys.org
If I understand what you are asking: can I use what seems to be an integer value and apply some arithmetic operator to it on a double precision variable without losing precision? In general, yes. Double precision on most systems is 15 digits of precision. That means the two operands and the result all have to fall within those bounds, or things may go wonky, precision-wise.

Promotion: from http://www.cs.uwm.edu/~cs151/Bacon/Lecture/HTML/ch06s09.html FORTRAN class notes.
Implicit Data Conversions
Promotions occur when a two different data types are operands to a mathematical operator. In all cases, the value of the lower ranking type is converted to the higher ranking type.

  1. double complex [ complex(8) ]
  2. complex [ complex(4) ]
  3. double precision [ real(8) ]
  4. real [ real(4) ]
  5. integer(8)
  6. integer [ integer(4) ]
  7. integer(2)

Promotion is defined as taking the variable with least precision and boosting it up to the precision of the other variable.
 
Specifically, is real*8 still fully compatible this way with newer version compilers? Also, do I lose anything with my simpler definition of pi?
 
avikarto said:
Specifically, is real*8 still fully compatible this way with newer version compilers? Also, do I lose anything with my simpler definition of pi?
You can always run a test. Calculate π using REAL*8 and calculate it using the KIND parameter. Compare the two results.
 
Thread 'Star maps using Blender'
Blender just recently dropped a new version, 4.5(with 5.0 on the horizon), and within it was a new feature for which I immediately thought of a use for. The new feature was a .csv importer for Geometry nodes. Geometry nodes are a method of modelling that uses a node tree to create 3D models which offers more flexibility than straight modeling does. The .csv importer node allows you to bring in a .csv file and use the data in it to control aspects of your model. So for example, if you...
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...
I am trying to run an .ipynb file and have installed Miniconda as well as created an environment as such -conda create -n <env_name> python=3.7 ipykernel jupyter I am assuming this is successful as I can activate this environment via the anaconda prompt and following command -conda activate <env_name> Then I downloaded and installed VS code and I am trying to edit an .ipynb file. I want to select a kernel, via VS Code but when I press the button on the upper right corner I am greeted...

Similar threads

Replies
4
Views
2K
Replies
25
Views
3K
Replies
4
Views
2K
Replies
4
Views
2K
Replies
59
Views
11K
Replies
8
Views
4K
Replies
20
Views
2K
Replies
8
Views
2K
Back
Top