operators - How does Python implement the modulo operation? -


i'm curious in regards time , space complexities of % operator in python. also, python use bitwise operation % 2?

edit: i'm asking python 2.7's implementation, in case differs of python 3

python uses classic algorithm d knuth's 'the art of computer programming'. running time (generally) proportional product of lengths of 2 numbers. space proportional sum of lengths of 2 numbers.

the actual division occurs in objects/longobject.c, see x_divrem(). background on internal representation of python long, see include/longintrepr.h.

% 2 not use bitwise operations. standard idiom checking if number even/odd & 1.

python 2 , 3 use same algorithm.


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -