Sunday, May 1, 2011

What does %% mean in code?

From the question you can probably tell that I don't know much about code! My question is this:

What does this code mean?

mnlong <- 280.460 + .9856474 * time
mnlong <- mnlong %% 360
mnlong[mnlong < 0] <- mnlong[mnlong < 0] + 360

I understand that the mnlong and time are variables but the %% confuses me.

Could someone give me a basic description.

Thanks

From stackoverflow
  • It's most likely that %% means integer division by modulo - the result is within 0..360 range. It's used for cases when some value can't get out of some reasonable range like longitute fo example that can be only within 0..360 degrees.

    Pip : thanks very much
    Luc M : The range is 0..359 because 360 modulo 360 is 0.
  • See: http://stackoverflow.com/questions/257717/position-of-the-sun-given-time-of-day-and-lat-long

  • Taking an educated guess that the language here is either R or S/Splus. As others have said: %% is the mod operator.

0 comments:

Post a Comment