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 - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -