[issue29815] Fail at divide a negative integer number for a positive integer number

2017-03-15 Thread Eryk Sun

Eryk Sun added the comment:

> -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: 

(-7 % 2) == -7 - 2 * (-7 // 2)
   1 == -7 - 2 * (-4)
 == -7 + 8

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.

--
nosy: +eryksun
resolution: rejected -> not a bug
status: open -> closed
type: crash -> behavior
versions:  -Python 3.3

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue29815] Fail at divide a negative integer number for a positive integer number

2017-03-15 Thread Marcos Thomaz

Marcos Thomaz added the comment:

Note that mathematic expression is wrong. -7 divided by 2 is -3, not -4

--
resolution:  -> rejected
type: behavior -> crash

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue29815] Fail at divide a negative integer number for a positive integer number

2017-03-15 Thread Marcos Thomaz

Marcos Thomaz added the comment:

Try this operations, in interactive environment:

>> 7 // 2
3
>> -7 // 2
-4

--
resolution: not a bug -> 
status: closed -> open
versions: +Python 3.3

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue29815] Fail at divide a negative integer number for a positive integer number

2017-03-15 Thread Marcos Thomaz

Marcos Thomaz added the comment:

I'm sorry, but was a typing error. Try this operations:

a, b, c = 7, -7, 2
print "1:", a // c, a % c
print "2:", b // c, b % c

the result is:
1: 3 1
2: -4 1

The division is the same, except by the signal (variable b is negative, but 
both, variables "a" and "b" are integers).

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue29815] Fail at divide a negative integer number for a positive integer number

2017-03-15 Thread Martin Panter

Martin Panter added the comment:

If you ignore the c[0] argument, the rest looks fine to me. See the 
documentation at 

 and 
.

The double-slash operator is called “floor division”. If you are expecting some 
other rounding, see 
.

--
nosy: +martin.panter
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed
type: crash -> behavior
versions:  -Python 3.3, Python 3.4

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue29815] Fail at divide a negative integer number for a positive integer number

2017-03-15 Thread Marcos Thomaz

New submission from Marcos Thomaz:

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
d = divmod(a, b)
print a//b, a%b, c[0], c // b, c%b

The values printed are -4  1 3 1

--
components: Interpreter Core
messages: 289647
nosy: marcosthomazs
priority: normal
severity: normal
status: open
title: Fail at divide a negative integer number for a positive integer number
type: crash
versions: Python 2.7, Python 3.3, Python 3.4, Python 3.5

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com