CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Main CFD Forum (https://www.cfd-online.com/Forums/main/)
-   -   fortran 77 - questions about code and math operations (https://www.cfd-online.com/Forums/main/177282-fortran-77-questions-about-code-math-operations.html)

mostanad September 9, 2016 11:44

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)

FMDenaro September 9, 2016 11:47

I think "1." is nothing else that a real instead of an integer

mostanad September 9, 2016 12:32

Quote:

Originally Posted by FMDenaro (Post 617289)
I think "1." is nothing else that a real instead of an integer

and what does it do? i think it is useless.

FMDenaro September 9, 2016 12:54

the array XC is defined as real so that does not generate mismatch (warning) during compilation.

agd September 9, 2016 14:11

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)

mostanad September 9, 2016 14:21

Quote:

Originally Posted by agd (Post 617304)
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)

thanks agd
but what is advantages of this kind of writing?

FMDenaro September 9, 2016 14:46

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

agd September 9, 2016 15:15

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.

mostanad September 9, 2016 15:23

Quote:

Originally Posted by agd (Post 617310)
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.

so "dot" between two numbers converts type of one of them to another one, then add numbers.That's ok?

agd September 9, 2016 15:56

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.

mostanad September 10, 2016 00:50

Quote:

Originally Posted by agd (Post 617313)
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.

Thanks agd
U teach a new lesson


All times are GMT -4. The time now is 14:44.