We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
Modulo Question (Read 921 times)
Modulo Question
Jun 10th, 2005, 7:27am
 
Hi All,

I stumbled across a calculating difference between Processing and MS Excel, I was hoping someone might explain the different results.

In a nested pair of loops I was testing...

Code:

for(intx=0;x<20;x++){
for(inty=0;y<20;y++){
if(2darray[x][(y+1)%20] != 0) {GiveAwayTheFortune();}
}
}


... when I checked the math in Excel I found that -1%20=19.
... when I println() the math I found that -1%20=-1.

I am doubting there is a "right" answer, so why the different standards?

Curious,

Jason
Re: Modulo Question
Reply #1 - Jun 10th, 2005, 4:38pm
 
i think it's a matter of what works depending on the context. for programming, the java way makes a little more sense. but maybe for excel, their version works better? or it's some legacy awfulness that was wrong but they're stuck with now? (anyone care to google?)

come to think of it the excel method strikes me as wrong, since % should be the remainder of an integer division. -1 / 20 is going to be 0, remainder -1 (if my, uh, basic math serves me?) so i guess they have some other version of how integer math works?
Re: Modulo Question
Reply #2 - Jun 11th, 2005, 3:30am
 
I'd agree with Fry, -1/20 is 0 rem -1, you can't end up with more (19) then you started with (-1) even if it is a negative value.
Page Index Toggle Pages: 1