Difference between revisions of "Modulo operation"
From Maths
(Saving work, stub page really) |
m (Alec moved page Modulo opeartion to Modulo operation without leaving a redirect: Typo in title) |
(No difference)
|
Latest revision as of 17:48, 7 January 2018
- Not to be confused with: Modulus operation - which is another name for absolute value
Definition
For [ilmath]a\in\mathbb{N}_0[/ilmath] and [ilmath]b\in\mathbb{N} [/ilmath] "[ilmath]a[/ilmath] modulo [ilmath]b[/ilmath]", written usually as a%b in most programming languages or using a mod(a,b) function is the remainder of dividing [ilmath]a[/ilmath] by [ilmath]b[/ilmath].
Implementation
I write this page because I have used:
- [math]a\% b\eq \Bigg(a-b\cdot[/math][math]\text{Floor} [/math][math]{\left(\frac{a}{b}\right)}\Bigg) [/math]
- Caveat:This only works for non-negative values! TODO: Proof?
- Caveat:This only works for non-negative values!
See also
Extensions
- What about negative numbers?
- [ilmath]2.5[/ilmath] mod [ilmath]1[/ilmath] is safely and obviously [ilmath]0.5[/ilmath] - this is quite common.