Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Full Precision Division Source

Tags:

python

c

division

I've been working with arbitrary-precision algorithms lately, and am exceedingly curious how Python goes about it. When I type a very large (600-1000) digits divided by another similarly large number, it just works and I love it. I have the Python source files and am okay with C, which / where in the source is the part that governs this division so I can look at it and maybe tinker with it? My end-game is number theory-type work in C.

like image 702
user1601118 Avatar asked Apr 09 '13 00:04

user1601118


1 Answers

The core of the implementation of long / long in Python 3.3 is in longobject.c, as the function x_divrem.

The implementation is modelled after Knuth's "The Art of Computer Programming", Vol. 2 (3rd edition), section 4.3.1, Algorithm D "Division of nonnegative integers", per a comment from the source.

like image 164
nneonneo Avatar answered Oct 21 '22 04:10

nneonneo