[PyQt] 2+1//(-10) == 1 and 2-1//10 == 2 !

Vadim Zelenin vadimzelenin at gmail.com
Wed Feb 3 01:30:28 GMT 2016


No, python calculates correctly.
Just the results differ from the results of these calculations in other
languages.

In python implemented the so-called floor-division:

https://docs.python.org/2/reference/expressions.html#binary-arithmetic-operations
https://docs.python.org/3/reference/expressions.html#binary-arithmetic-operations
https://www.python.org/dev/peps/pep-0238/
http://python-history.blogspot.ru/2010/08/why-pythons-integer-division-floors.html


2016-02-03 2:30 GMT+03:00 Miguel Alejandro Fernandez <
alejandrogroso at hotmail.com>:

> Error python, not have the slightest sense!
>
>
> Python 3.4.2 (v3.4.2:ab2c023a9432, Oct  6 2014, 22:15:05) [MSC v.1600 32
> bit (In
> tel)] on win32
> Type "help", "copyright", "credits" or "license" for more information.
> >>>
> >>>
> >>>
> >>> 5//50, 5%50
> (0, 5)
> >>>
> >>>
> >>> -1//50, -1%50
> (-1, 49)
> >>>
> >>>
> >>>
> >>> -1//50
> -1
> >>>
> >>>
> >>> -1/50
> -0.02
> >>>
> >>>
> >>>
> >>> -1/10
> -0.1
> >>>
> >>>
> >>> -(1//10)
> 0
> >>>
> >>> -21//10
> -3
> >>>
> >>> -2//10
> -1
> >>>
> >>>
> >>> -1.0//10
> -1.0
> >>>
> >>>
> >>>
> >>>
> >>>
> >>> -1.0//10.0
> -1.0
> >>>
> >>> 0//10
> 0
> >>>
> >>>
> >>>
> >>> 0//10.0
> 0.0
> >>>
> >>>
> >>>
> >>> 2//10.0
> 0.0
> >>> 1//10.0
> 0.0
> >>>
> >>>
> >>>
> >>>
> >>> -1//10
> -1
> >>> 2//10.0
> 0.0
> >>>
> >>>
> >>> -1//10.0
> -1.0
> >>>
> >>>
> >>>
> >>> -10//10.0
> -1.0
> >>> -20//10.0
> -2.0
> >>>
> >>>
> >>>
> >>> 2-1//10
> 2
> >>>
> >>>
> >>> -1//10
> -1
> >>>
> >>> 2+1//(-10)
> 1
> >>>
> >>> 1//(-10)
> -1
> >>> +1//(-10)
> -1
> >>>
> >>>
>
>
>
> pypy-2.4.0-win32 also returns the same results.
>
>
> any ideas?
>
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> https://www.riverbankcomputing.com/mailman/listinfo/pyqt
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20160203/0993f44c/attachment.html>


More information about the PyQt mailing list