if statement - How would this Fortran conditional expression evaluate? -


in fortran95 code below variable nmom integer , equal 3.

what value of p0 evaluate to, 1 or -1? divide 2 multiply 2 bit has me confused, i'm not sure why this, written non-programmer scientist in 90s no longer around ask.

p0=1 if(nmom-nmom/2*2.eq.1)p0=-1 

the code compiled lf95 on linux machine.

i don't know fortran, guess is testing if nmom odd or even. first, rewrite parens simulate operator precedence:

if(nmom-((nmom/2)*2).eq.1)p0=-1 

and if using integer math (nmom/2)*2 == nmom if it's else equal nmom-1 if it's odd.


Comments

Popular posts from this blog

php - mySql Join with 4 tables -

css - Text drops down with smaller window -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -