What is happening here? Why is the first calculation returning an integer, but not the second calculation? What are the rules for computing mod for floats and negative numbers?
Asked
Active
Viewed 483 times
0
-
Have you tried reading the Wikipedia article on modulo? – john_leo Oct 21 '14 at 08:53
2 Answers
2
I just think it extended classic rules. $$2\times\frac{21}{2} - 16 = 5$$ So $-16 = 5 \mod \frac{21}{2}$
A. Breust
- 305
1
Mathematically $x\bmod y$ means $x-ky$ with $k\in\Bbb Z$ such that $ky$ is the largest integer multiple of $y$ for which $ky\leq x$ (at least this is the definition when $y>0$; when $y<0$ conventions vary). In your example $k=-2$ both times, so $ky=-21$ respectively $ky\approx-21.069$.
By the way, most computer hardware designers either didn't understand the mathematical meaning of $\bmod$ our found it too hard to implement, so that most computer hardware implements a different remainder operation (at least when $x,y$ are integers). See here. But the calculator software does seem to get it right here.
Marc van Leeuwen
- 115,048

