Template:Mod

From Traveller Wiki - Science-Fiction Adventure in the Far future
Jump to navigation Jump to search

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