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.
IndexSuggestions & BugsWebsite,  Documentation,  Book Bugs › Examples for % (modulo) in the reference
Page Index Toggle Pages: 1
Examples for % (modulo) in the reference (Read 1469 times)
Examples for % (modulo) in the reference
Jan 29th, 2010, 2:24pm
 
These are the examples for % (modulo) on Processing reference, are they ok?

int a = 20%100;         // Sets a to 20
int b = 20%100;         // Sets b to 20
float c = 75.0%100.0;   // Sets c to 75.0
float d = 275.0%100.0;  // Sets d to 75.0

I believe it should set the variable to the remainder of the two terms, not to the first term.
Re: Examples for % (modulo) in the reference
Reply #1 - Jan 30th, 2010, 1:20am
 
that's what they are doing - look at the 4th example.

i agree that the other values are badly chosen and don't really show what's going on. and there needs to be a negative example as well because -8 % 6 = -2 and not 4 like you might expect (because -2 is not in the range 0-5)
Re: Examples for % (modulo) in the reference
Reply #2 - Jan 30th, 2010, 1:48am
 
Just try them... Smiley
But indeed, b should be 320%100 for example.
Page Index Toggle Pages: 1