Modulo: Difference between revisions
Jump to navigation
Jump to search
(Created page with "{{stub}} <!-- Conceptually, modulo is the remainder after a division. (not to be confused with modulus, which [http://jeff560.tripod.com/m.html has a few other meanings in...") |
mNo edit summary |
||
Line 4: | Line 4: | ||
Conceptually, modulo is the remainder after a division. | Conceptually, modulo is the remainder after a division. | ||
In programming languages, if it has an operation as a single character in the language, that's usually {{inlinecode||%}} | |||
In integer math, | |||
7 / 4 = 1 | |||
7 % 4 = 3 | |||
And a little more practically | |||
def is_even(n): | def is_even(n): | ||
return n%2 == 0 | return n%2 == 0 | ||
Line 29: | Line 23: | ||
if i%27==0: | if i%27==0: | ||
print "at job",i | print "at job",i | ||
Notes: | |||
* Not to be confused with ''modulus'', which [http://jeff560.tripod.com/m.html has a few other meanings in mathematics] though in programming context usually 'absolute value'. | |||
* The modulo operation can sometimes be optimized, e.g. modulo of powers of two (not unusual in programming) have a bitwise-AND equivalent. | |||
--> | --> |
Revision as of 14:01, 12 October 2023
✎ This article/section is a stub — some half-sorted notes, not necessarily checked, not necessarily correct. Feel free to ignore, or tell me about it.