Arbitrary precision integer arithmetic: ceiling?

Mark Dickinson dickinsm at gmail.com
Sat Mar 8 21:27:27 EST 2008


On Mar 8, 9:19 pm, "Terry Reedy" <tjre... at udel.edu> wrote:
> Obvious typo: -(-a)//b == a//b
>
> This should be -(-a//b) == -((-a)//b)

Yes:  thanks for the correction!

A lesson to me to include parentheses even when redundant...

This reminds me of the following parenthesization gem
(see next to last line):

def isqrt(n):
    """Find the closest integer to sqrt(n), for n a positive
integer."""
    a, b = n, 1
    while a != b:
        a, b = a -- n // a >> 1, a
    return a

Mark



More information about the Python-list mailing list