Integer division in Python 3

Status
Not open for further replies.

zeotherm

Ars Legatus Legionis
10,960
Moderator
A python question for the gurus: How does python 3+ handle integer division?

I ported an elliptic curve factorization library to python 3 and it is now running considerably slower then its python 2.X equivalent. The only real math part that was affected was the change from int / int (which now returns a float in Python 3) to int // int which they (Python docs) refer to as floor division. My (completely wild-ass speculation) is that int // int is getting transformed to math.floor(float / float), but I have no idea if that is true. It would explain things though. Does any one know how this is handled or where I can find out for sure? Thanks.
 

tuffy

Ars Scholae Palatinae
972
It might have to do with Python 3 removing the classic int type and moving all int operations to longs. If you compare Python2's Objects/intobject.c's i_divmod() function to Python3's Objects/longobject.c's x_divrem(), the latter is considerably more complex to account for arbitrarily long values. That's my hunch from looking through the source code, but I haven't benchmarked it to be sure.
 
Status
Not open for further replies.