Template:Mod: Difference between revisions

From Meta, a Wikimedia project coordination wiki
Content deleted Content added
* {{mod|123|(2^32-1)}} → 123 * {{#expr:123mod(2^32-1)}} → 0 (wrong)
divisor, Template:Modint
Line 2: Line 2:
Implements the mathematical [[w:en:modulo|modulo]] operator. It should not be confused with the parser function [[ParserFunctions#.23expr:|mod]] (remainder of division after truncating both operands to an integer).
Implements the mathematical [[w:en:modulo|modulo]] operator. It should not be confused with the parser function [[ParserFunctions#.23expr:|mod]] (remainder of division after truncating both operands to an integer).


The returned result is always of the same sign as the ''modulus'' or nul, and its absolute value is lower than the absolute value of the ''modulus''. However, this template returns 0 if the ''modulus'' is nul (this template should never return a division by zero error).
The returned result is always of the same sign as the divisor or zero, and its absolute value is lower than the absolute value of the divisor. However, this template returns 0 if the divisor is nul (this template should never return a division by zero error).


; Usage<nowiki>:</nowiki>
; Usage<nowiki>:</nowiki>
: <tt><nowiki>{{</nowiki>{{PAGENAME}}|</tt>''dividend''<tt>|</tt>''modulus''<tt><nowiki>}}</nowiki></tt>
: <tt><nowiki>{{</nowiki>{{PAGENAME}}|</tt>''dividend''<tt>|</tt>''divisor''<tt><nowiki>}}</nowiki></tt>


; Examples with positive integer modulus<nowiki>:</nowiki>
; Examples with positive integer modulus<nowiki>:</nowiki>
Line 65: Line 65:
From {{tiw|en|mod}}.
From {{tiw|en|mod}}.


See also [[Help:Modulo and round]].
See also:
*[[Template:Modint]]
*[[Help:Modulo and round]].


[[Category:Mathematical templates|{{PAGENAME}}]]
[[Category:Mathematical templates|{{PAGENAME}}]]

Revision as of 11:01, 21 October 2010

Implements the mathematical modulo operator. It should not be confused with the parser function mod (remainder of division after truncating both operands to an integer).

The returned result is always of the same sign as the divisor or zero, and its absolute value is lower than the absolute value of the divisor. However, this template returns 0 if the divisor is nul (this template should never return a division by zero error).

Usage:
{{Mod|dividend|divisor}}
Examples with positive integer modulus:
  • {{Mod|12|10}} = 2.
  • {{Mod|10.1|10}} = 0.1.
    • compare: {{#expr:10.1 mod 10}} = 0.
  • {{Mod|10|10}} = 0.
  • {{Mod|2|10}} = 2.
  • {{Mod|0|10}} = 0.
  • {{Mod|-2|10}} = -2.
  • {{Mod|-10|10}} = 0.
  • {{Mod|-10.1|10}} = -0.1.
  • {{Mod|-12|10}} = -2.
Examples with negative integer modulus:
  • {{Mod|12|-10}} = 2.
  • {{Mod|10.1|-10}} = 0.1.
  • {{Mod|10|-10}} = 0.
  • {{Mod|2|-10}} = 2.
  • {{Mod|0|-10}} = 0.
  • {{Mod|-2|-10}} = -2.
  • {{Mod|-10|-10}} = 0.
  • {{Mod|-10.1|-10}} = -0.1.
  • {{Mod|-12|-10}} = -2.
Examples with positive non integer modulus:
  • {{Mod|21.5|10.5}} = 0.5.
    • compare: {{#expr:21.5 mod 10.5}} = 1.
  • {{Mod|21.1|10.5}} = 0.1.
  • {{Mod|21|10.5}} = 0.
  • {{Mod|20.9|10.5}} = 10.4.
  • {{Mod|11|10.5}} = 0.5.
  • {{Mod|10.6|10.5}} = 0.1.
  • {{Mod|10.5|10.5}} = 0.
  • {{Mod|10.1|10.5}} = 10.1.
  • {{Mod|10|10.5}} = 10.
  • {{Mod|2|10.5}} = 2.
  • {{Mod|0|10.5}} = 0.
  • {{Mod|-2|10.5}} = -2.
  • {{Mod|-10|10.5}} = -10.
  • {{Mod|-10.1|10.5}} = -10.1.
  • {{Mod|-10.5|10.5}} = 0.
  • {{Mod|-10.6|10.5}} = -0.1.
  • {{Mod|-11|10.5}} = -0.5.
  • {{Mod|-20.9|10.5}} = -10.4.
  • {{Mod|-21|10.5}} = 0.
  • {{Mod|-21.1|10.5}} = -0.1.
  • {{Mod|-21.5|10.5}} = -0.5.
Examples with nul modulus:
  • {{Mod|2|0}} = 0.
  • {{Mod|0|0}} = 0.
  • {{Mod|-2|0}} = 0.
  • {{subst:Mod|12|7|subst=subst:}} = 5.
  • {{mod|123|(2^32-1)}} → 123
  • {{#expr:123mod(2^32-1)}} → 123 (wrong)

From w:en:Template:Mod.

See also: