Page 1 of 1

Wire Modulo Node giving incorrect value for negative inputs

Posted: Wed Feb 15, 2023 07:24
by samTrolland
It looks like the Wire node 'Modulo' gives incorrect values for negative numerator inputs.

Example according to Wolfram Alpha:
11 mod 7 = 4
-11 mod 7 = 3

In Wire:
11 mod 7 = 4 (correct)
-11 mod 7 = -4 (incorrect)
Screen Shot 2023-02-15 at 5.20.44 pm.png
Screen Shot 2023-02-15 at 5.19.13 pm.png
Screen Shot 2023-02-15 at 5.19.13 pm.png (8.56 KiB) Viewed 944 times
Screen Shot 2023-02-15 at 5.20.30 pm.png
Screen Shot 2023-02-15 at 5.19.33 pm.png
Screen Shot 2023-02-15 at 5.19.33 pm.png (8.29 KiB) Viewed 944 times

Re: Wire Modulo Node giving incorrect value for negative inputs

Posted: Wed Feb 15, 2023 08:14
by samTrolland
The correct Modulo result for negative inputs can be achieved in Wire using a few extra logic nodes:

If the Modulo Result is less than 0 then add the denominator to the result.

-11 mod 7 = 3 (correct)
Screen Shot 2023-02-15 at 6.11.31 pm.png
11 mod 7 = 4 (correct)
Screen Shot 2023-02-15 at 6.11.42 pm.png

Re: Wire Modulo Node giving incorrect value for negative inputs

Posted: Wed Feb 15, 2023 18:06
by Zoltán
There are some ways to do mod, looks like wolfram does a different one than Wire.
If you try the same in Processing you get the same result as in Wire.