New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fail at divide a negative integer number for a positive integer number #74001
Comments
At divide a negative integer number for a positive integer number, the result is wrong. For example, in operation: a, b, c = -7, 2, 7 The values printed are -4 1 3 1 |
If you ignore the c[0] argument, the rest looks fine to me. See the documentation at <https://docs.python.org/2/reference/expressions.html#binary-arithmetic-operations\> and <https://docs.python.org/2/library/stdtypes.html#numeric-types-int-float-long-complex\>. The double-slash operator is called “floor division”. If you are expecting some other rounding, see <https://docs.python.org/2/faq/programming.html#why-does-22-10-return-3\>. |
I'm sorry, but was a typing error. Try this operations: a, b, c = 7, -7, 2 the result is: The division is the same, except by the signal (variable b is negative, but both, variables "a" and "b" are integers). |
Try this operations, in interactive environment:
|
Note that mathematic expression is wrong. -7 divided by 2 is -3, not -4 |
Integer division in Python is floor division, and it's self-consistent with the implementation of the modulo operation such that the following identity is satisfied: (a % n) == a - n * (a // n). For example:
This behavior is consistent with mathematical analysis languages such as MATLAB, Mathematica, Mathcad, and R. It's also consistent with Ruby, Perl, and Tcl. However, it's different from C, C++, C#, Java, PHP and many other languages. See the following Wikipedia article: https://en.wikipedia.org/wiki/Modulo_operation Please do not change the status and resolution of this issue again. This is not a bug. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: