Template:Mod: Difference between revisions

From Meta, a Wikimedia project coordination wiki
Content deleted Content added
No edit summary
It should not be confused with the parser function mod (remainder of division after truncating both operands to an integer).
Line 1: Line 1:
<includeonly>{{#ifexpr:({{{2|}}})=0|0|{{#ifexpr:(({{{1|}}})/({{{2|}}}))=((({{{1|}}})/({{{2|}}}))round 0)|0|{{#ifexpr:(({{{1|}}})/({{{2|}}}))>0 and(({{{1|}}})/({{{2|}}}))<1|{{#expr:{{{1|}}}}}|{{#expr:({{{1|}}})-((((({{{1|}}})/({{{2|}}}))-0.5)round 0)*({{{2|}}}))}}}}}}}}</includeonly><noinclude>
<includeonly>{{#ifexpr:({{{2|}}})=0|0|{{#ifexpr:(({{{1|}}})/({{{2|}}}))=((({{{1|}}})/({{{2|}}}))round 0)|0|{{#ifexpr:(({{{1|}}})/({{{2|}}}))>0 and(({{{1|}}})/({{{2|}}}))<1|{{#expr:{{{1|}}}}}|{{#expr:({{{1|}}})-((((({{{1|}}})/({{{2|}}}))-0.5)round 0)*({{{2|}}}))}}}}}}}}</includeonly><noinclude>
Implements the mathematical [[w:en:modulo|modulo]] operator. 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).
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).


; Usage<nowiki>:</nowiki>
; Usage<nowiki>:</nowiki>

Revision as of 11:09, 26 May 2006

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 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).

Usage:
{{Mod|dividend|modulus}}
Examples with positive 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}} = 8.
  • {{Mod|-10|10}} = 0.
  • {{Mod|-10.1|10}} = 9.9.
  • {{Mod|-12|10}} = 8.
Examples with negative integer modulus:
  • {{Mod|12|-10}} = -8.
  • {{Mod|10.1|-10}} = 0.1.
  • {{Mod|10|-10}} = 0.
  • {{Mod|2|-10}} = -8.
  • {{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.
  • {{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}} = 8.5.
  • {{Mod|-10|10.5}} = 0.5.
  • {{Mod|-10.1|10.5}} = 0.4.
  • {{Mod|-10.5|10.5}} = 0.
  • {{Mod|-10.6|10.5}} = 10.4.
  • {{Mod|-11|10.5}} = 10.
  • {{Mod|-20.9|10.5}} = 0.1.
  • {{Mod|-21|10.5}} = 0.
  • {{Mod|-21.1|10.5}} = 10.4.
  • {{Mod|-21.5|10.5}} = 10.
Examples with nul modulus:
  • {{Mod|2|0}} = 0.
  • {{Mod|0|0}} = 0.
  • {{Mod|-2|0}} = 0.

From w:en:Template:Mod.