[Python-ideas] Add the imath module

Serhiy Storchaka storchaka at gmail.com
Thu Jul 12 09:11:33 EDT 2018


12.07.18 14:55, Serhiy Storchaka пише:
> What are your thoughts about adding a new imath module for integer 
> mathematics? It could contain the following functions:

I forgot yet one useful function:

def divide_and_round(a, b):
     q, r = divmod(a, b)
     r *= 2
     greater_than_half = r > b if b > 0 else r < b
     if greater_than_half or r == b and q % 2 == 1:
         q += 1
     return q

(This is a copy of the implementation from datetime.py, there are yet 
few implementations in Python and C in other files.)



More information about the Python-ideas mailing list