Left here for archival purposes.

User avatar
By picstart1
#4499
(-1000) mod 10000 = 9000

The correct answer is always 9000. Modulo has a strict mathematical definition.
To move to -1000 from an arbitrary modulo zero position (say 10000) involves two retrograde steps of 10,000 and the last step has a remainder of 9000. The result of a Modulo operation is the remainder.
Coders often see coding as a mathematical skill often times they just don't get mathematics. Rounding is a good example.
When changing base notation from decimal to binary except for numbers that can be expressed as a power series in the number two there is a mathematical difference.
Coders call this rounding. It is not it is just that binary notation to a specific precision is different than decimal. EX 1/10 is 0.1 in decimal but can't be notated in binary with limited precision.
1/3 in decimal is an equivalent example .
Now coders using a handheld calculator are sometimes unaware that the calculator uses binary coded decimal so never is base conversion an issue.
User avatar
By sancho
#4500
picstart1 wrote:The correct answer is always 9000. Modulo has a strict mathematical definition.
To move to -1000 from an arbitrary modulo zero position (say 10000) involves two retrograde steps of 10,000 and the last step has a remainder of 9000. The result of a Modulo operation is the remainder.

Thanks, the same thing occured to me in the morning - was playing with the script (and running back and forth to freezer with the sensor) until midnight :)
User avatar
By picstart1
#4503
(-1000) mod 10000 = 9000

The issue here is that with (-1000) the - is an infix operation it only sets the sign. Now
-(1000 mod 10000)
is different in that the bracket causes the mod to operate on 1000 prior to infix setting the sign.