|
[Sponsors] |
fortran 77 - questions about code and math operations |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
September 9, 2016, 12:44 |
fortran 77 - questions about code and math operations
|
#1 |
Senior Member
mohammad
Join Date: Sep 2015
Posts: 279
Rep Power: 12 |
hello everybody
what is the meaning of below command in fortran 77? "1.-parameter" Code:
XC2(I,J)=1.-XC(II,J) |
|
September 9, 2016, 12:47 |
|
#2 |
Senior Member
Filippo Maria Denaro
Join Date: Jul 2010
Posts: 6,849
Rep Power: 73 |
I think "1." is nothing else that a real instead of an integer
|
|
September 9, 2016, 13:32 |
|
#3 |
Senior Member
mohammad
Join Date: Sep 2015
Posts: 279
Rep Power: 12 |
||
September 9, 2016, 13:54 |
|
#4 |
Senior Member
Filippo Maria Denaro
Join Date: Jul 2010
Posts: 6,849
Rep Power: 73 |
the array XC is defined as real so that does not generate mismatch (warning) during compilation.
|
|
September 9, 2016, 15:11 |
|
#5 |
Senior Member
Join Date: Jul 2009
Posts: 357
Rep Power: 19 |
It's not useless. The value of XC(II,J) is being subtracted from 1.0, and the result is put into XC2(I,J), as in
xc2(i,j) = 1 - xc(ii,j) |
|
September 9, 2016, 15:21 |
|
#6 |
Senior Member
mohammad
Join Date: Sep 2015
Posts: 279
Rep Power: 12 |
||
September 9, 2016, 15:46 |
|
#7 |
Senior Member
Filippo Maria Denaro
Join Date: Jul 2010
Posts: 6,849
Rep Power: 73 |
1 is an integer while 1. is a REAL*4 type (1d0 would be a REAL*8, that is a double precision) ... doing a mixed types operation like (integer) - (real), the compiler have to do the conversion in the same type of the variable in which you store the result of the difference.
If you use aggressive debugging option, the operation would result in a warning |
|
September 9, 2016, 16:15 |
|
#8 |
Senior Member
Join Date: Jul 2009
Posts: 357
Rep Power: 19 |
What FMDenaro said. It forces an explicit type conversion, since XC is a real variable (assuming the standard FORTRAN variable naming conventions) so that you add a real to a real.
|
|
September 9, 2016, 16:23 |
|
#9 |
Senior Member
mohammad
Join Date: Sep 2015
Posts: 279
Rep Power: 12 |
so "dot" between two numbers converts type of one of them to another one, then add numbers.That's ok?
|
|
September 9, 2016, 16:56 |
|
#10 |
Senior Member
Join Date: Jul 2009
Posts: 357
Rep Power: 19 |
No - you're overthinking it. That dot is just a decimal point, as in 1.0 or 25.4. FORTRAN by default treats all numbers with decimal points as real, and those without decimal points as integers. It would be clearer if the original programmer had written it as
XC2(I,J) = 1.0 - XC(II,J) but many programmers get lazy and write simple floats as 1. or 65. rather than 1.0 or 65.0. |
|
September 10, 2016, 01:50 |
|
#11 | |
Senior Member
mohammad
Join Date: Sep 2015
Posts: 279
Rep Power: 12 |
Quote:
U teach a new lesson |
||
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Comparison between C/C++ and Fortran? | rick | Main CFD Forum | 45 | September 6, 2011 01:52 |
Fortran 90 faster than C/C++ | B. R. Guirguis | Main CFD Forum | 48 | March 6, 2006 14:49 |