I guessed that 5% 2 is 1, -5% 2 - -1
But, in Python, I get the same result.
I think this is not a mathematical problem.
>>> -5 % 2 1 ( I think this should be -1 ) >>> 5 % 2 1 >>> -7 % 6 5 ( I think this should be -1 ) >>> 7 % 6 1
Why? Since the modulo operator is defined this way in python.
The documentation states:
The modulo operator always gives a result with the same sign as its second operand (or zero); [...]
and
The function math.fmod()returns a result whose sign matches the sign of the first argument, [...] Which approach is more dependent on the application.
math.fmod()
%, , . , m % n Z [n], m, Z [n] - , 0, 1, 2,..., n, n. , , , 0, 0, 1, 2,..., n Z [n].
%
m % n
( ) . , Z [n], . , , , Python % - , n.
( , n) , .
Source: https://habr.com/ru/post/1684190/More articles:How to set values with different time intervals? - sqlChanging the skin of players using NMS in Minecraft (Bukkit / Spigot) - javaHow to make a turn for the request below? - sql-serverHow to create a form in Drupal 7 with saving data in the admin panel and export data to excel? - phpautomatic click on the download is larger, but the automatic click only starts after the first manually click - javascriptAVCAM example - Swift Xcode v9 - swiftWordpress показывает сообщения в таблице, иначе echo- loopshow php echo individual column values of a row of a result from a mysql query? - phpPreventing routing in Response when a user manually changes the URL on a browser tab - reactjsPush new node in firebase, if not - objective-cAll Articles