Fortran Fortran77: What does a period in the middle of an eq mean?

AI Thread Summary
In Fortran 77, the period in the expression R(1)=2.*RL(1)*N(1) indicates that the number 2 is treated as a floating-point value rather than an integer. This distinction is crucial because using an integer could lead to truncation issues when assigning the result to R(1). The period serves as a radix point, ensuring that the compiler recognizes the value as a float, which is important for maintaining precision in calculations. While many modern compilers may automatically convert integers to floats, it's considered best practice to explicitly use a float (e.g., 2. or float(2)) to avoid potential problems in the program's execution.
dimensionless
Messages
460
Reaction score
1
I'm trying to comprehend some old Fortran 77 code. I've run across an a line of code that resembles the following:
Code:
R(1)=2.*RL(1)*N(1)
What does the period in the above code mean?
 
Technology news on Phys.org
I'm no Fortran expert, but I'll make an educated guess:
I suspect the period is there simply to indicate to the compiler that the "2" is a float variable rather than an integer. Without the period, the compiler might treat the "2" as an integer, which could cause problems elsewhere in the program.
 
http://www.ictp.trieste.it/~manuals/programming/sun/fortran/f77rm/1_elements.doc.html has list of fortran symbols. According to them the period(.) is a Radix point, delimiter for logical constants and operators, record fields.
 
Last edited by a moderator:
DuncanM has it corretct, 2 is an integer, 2. a float. Also can be written as

R(1)=float(2)*RL(1)*N(1)
 
When does the period need to be used?
 
If you want R(1) to be a float, you have to use either 2. or float(2) in the expression, if not R(2) probably will be truncated to an integer value. Many of the more recent compilers will overlook this and convert it to a float variable, it is just good programming practice to have it in there or else you may have problems down the road.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...

Similar threads

Replies
20
Views
3K
Replies
1
Views
3K
Replies
5
Views
3K
Replies
2
Views
2K
Replies
9
Views
2K
Replies
5
Views
5K
Replies
1
Views
2K
Replies
2
Views
3K
Replies
4
Views
2K
Back
Top