fortran 77 - questions about code and math operations
hello everybody
what is the meaning of below command in fortran 77? "1.-parameter" Code:
XC2(I,J)=1.-XC(II,J) |
I think "1." is nothing else that a real instead of an integer
|
Quote:
|
the array XC is defined as real so that does not generate mismatch (warning) during compilation.
|
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) |
Quote:
but what is advantages of this kind of writing? |
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 |
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.
|
Quote:
|
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. |
Quote:
U teach a new lesson |
All times are GMT -4. The time now is 14:44. |