TITLE: Why do so many computer programming language implementations have trouble with the remainders of negative integers?
QUESTION [12 upvotes]: As most of us know, or should know, $-7 \equiv 1 \pmod 4$.
But if you use Java's modulus operator %, you get -3 for the answer, not 1. That's technically correct, but it can cause problems if you're not aware of this as you write a program. C# and Javascript are the same way.
Worse, there are varieties of BASIC which will give you the remainder of the absolute value, e.g., 3 for the example of $-7$; that's clearly wrong.
It looks like only Maple and Mathematica (and by extension, Wolfram Alpha) know better.
Why is this?

REPLY [4 votes]: Hint:
  The paper The Euclidean Definition of the Functions $\mathrm{div}$ and $\mathrm{mod}$ by R.T. Boute provides an in-depth discussion of different definitions in mathematics and programming languages.

I'm a great fan of D.E. Knuth and since his F-definition (flooring the quotient and rounding toward negative infinity) is addressed in the paper as one of two preferred approaches, I also recommend reading section 3.4 '$\mathrm{MOD}$' - THE BINARY OPERATION in Concrete Mathematics.