Is the modulo operation signature in sync with the mathematical definition?

Yes, you are right in all your points. Mainly:

  • It is not violating the mathematical definition.
  • Maths does not know about Long or Int or any other programming language type.

But it is true as well that the remainder, by definition (remainder part is going to be lower than the divisor part), always is going to in the divisor type.

The issue that I had was that I did not cast the result of the modulo to Int, so I was serializing and storing it as Long. In this way, the size in memory (and in the disk as well) was the double I was expecting.

So as a takeaway:

Scala is returning the same type that Java to avoid the performance penalty of casting.

Am I right?