Arbitrary precision integer arithmetic: ceiling?

Mark Dickinson dickinsm at gmail.com
Sat Mar 8 20:09:11 EST 2008


On Mar 8, 6:26 pm, Paul Rubin <http://phr...@NOSPAM.invalid> wrote:
> Alasdair <amc... at gmail.com> writes:
> > What is the best way of finding a ceiling of a quotient of arbitrary sized
> > integers?
>
> ceiling(a/b) = (a+b-1)//b

I prefer:

ceiling(a/b) = -(-a)//b

which also works if a and b are something other
than integers (e.g. rational numbers).

Mark



More information about the Python-list mailing list