Difference between revisions of "Template:Mod"

From Traveller Wiki - Science-Fiction Adventure in the Far future
Jump to navigation Jump to search
 
(One intermediate revision by the same user not shown)
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 divisor or zero, and its absolute value is lower than the absolute value of the divisor. This allows this template to be fully compatible with cyclic modular arithmetic (for exampel in calendar computations).
+
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. This allows this template to be fully compatible with cyclic modular arithmetic (for example in calendar computations).
  
 
For example if the given ''modulus'' is 10, the result will always be positive or null and lower than 10 (all ''dividend'' values in that positive range will be returned without change). This is not true with the <tt>mod</tt> and <tt>fmod</tt> operators in expressions evaluated with the <tt><nowiki>#expr:</nowiki></tt> ParserFunction extension of MediaWiki.
 
For example if the given ''modulus'' is 10, the result will always be positive or null and lower than 10 (all ''dividend'' values in that positive range will be returned without change). This is not true with the <tt>mod</tt> and <tt>fmod</tt> operators in expressions evaluated with the <tt><nowiki>#expr:</nowiki></tt> ParserFunction extension of MediaWiki.
  
 
However, this template returns 0 if the divisor is null (this template should never return any division by zero error).
 
However, this template returns 0 if the divisor is null (this template should never return any division by zero error).
[[Category: Templates|{{{PAGENAME}}}]]
+
[[Category: Math Templates|{{PAGENAME}}]]
 
</noinclude>
 
</noinclude>

Latest revision as of 12:30, 22 July 2018

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. This allows this template to be fully compatible with cyclic modular arithmetic (for example in calendar computations).

For example if the given modulus is 10, the result will always be positive or null and lower than 10 (all dividend values in that positive range will be returned without change). This is not true with the mod and fmod operators in expressions evaluated with the #expr: ParserFunction extension of MediaWiki.

However, this template returns 0 if the divisor is null (this template should never return any division by zero error).