Linked Questions

0 votes
4 answers
296 views

How python calculate mathematically this modulo? >>>-1%10 9
Federico's user avatar
1 vote
1 answer
84 views

How to get the same values ​​in Python as in C++? CPP code #include <bitset> #include <iostream> using namespace std; int main() { short int divider = -32768; auto ...
phpusr's user avatar
  • 39
0 votes
1 answer
171 views

for instance,-10 % 3 = 2, this does not make any sense as the definition for % is remainder. Thanks
Tony's user avatar
  • 39
2 votes
1 answer
111 views

When a-b*i becomes negative, why is -8 % 5 2, rather than 3 or -3, when using Python 2.7. a = 12 b = 5 for i in range(10): print a-b*i, (a-b*i) % b 12 2 7 2 2 2 -3 2 -8 2 -13 2 -18 2 -23 2 -28 ...
Lin Ma's user avatar
  • 10.2k
0 votes
1 answer
62 views

Why -4%5 => 1 //I understand -5%5 => 0 //I understand -6%5 => 4 // My mind has been deleted I checked it in c/cpp, there result is just -1.
Marcin Ziajkowski's user avatar
0 votes
0 answers
81 views

I'm learning Python and I wish to know why "-40//60 = -1" and "-40 % 60 = 20" My solution to this problem was turning the values to positive, but I don't get why it is returning ...
kruffer's user avatar
0 votes
0 answers
78 views

What is the justification for the result of x % a being negative whenever a is negative, in Python 3? In mathematics, modulo is not typically considered an operator, but rather a modifier on the ...
Noldorin's user avatar
  • 148k
0 votes
0 answers
78 views

For example why 2 %-8 results in -6? I was reading What is the result of % in Python? nut I didn't manage to get it, for example I read in comments exaplanation of 7%2 its 7-2=5 and then 5-2 = 3 and ...
BugsForBreakfast's user avatar
0 votes
0 answers
55 views

this answer explains the modulo operation for positive numbers perfectly. But how does modulo operation work differently for negative integers? for example -1 % 60 == 59 in Python but -1 % 60 == -1 in ...
computronium's user avatar
0 votes
0 answers
22 views

when Iam performing modular division on negative numbers,I found that it is not same as in case of positive numbers I've tried >>> -123%10 7 >>> 123%10 3 I expected that the output ...
Sai Krishna Maddali's user avatar
4027 votes
36 answers
617k views

Consider the following code: 0.1 + 0.2 == 0.3 -> false 0.1 + 0.2 -> 0.30000000000000004 Why do these inaccuracies happen?
Cato Johnston's user avatar
33 votes
4 answers
52k views

I have failed to find documentation for the operator % as it is used on strings in Python. What does this operator do when it is used with a string on the left hand side?
Ram Rachum's user avatar
  • 89.5k
14 votes
2 answers
6k views

With simple ints: >>> -45 % 360 315 Whereas, using a decimal.Decimal: >>> from decimal import Decimal >>> Decimal('-45') % 360 Decimal('-45') I would expect to get Decimal(...
zezollo's user avatar
  • 5,107
10 votes
4 answers
7k views

Questions arise when I type in these expressions to Python 3.3.0 -10 // 3 # -4 -10 % 3 # 2 10 // -3 # -4 10 % -3 # -2 -10 // -3 # 3 It appears as though it takes the approximate floating ...
tlands_'s user avatar
  • 166

15 30 50 per page