Arbitrary precision integer arithmetic: ceiling?

Terry Reedy tjreedy at udel.edu
Sat Mar 8 21:19:56 EST 2008


"Steven D'Aprano" <steve at REMOVE-THIS-cybersource.com.au> wrote in message 
news:13t6gf5on1qnhbe at corp.supernews.com...
| On Sat, 08 Mar 2008 17:09:11 -0800, Mark Dickinson wrote:
|
| > 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

Obvious typo: -(-a)//b == a//b

This should be -(-a//b) == -((-a)//b)

| Unfortunately it doesn't give the right answer.
| Looks like you've confused ceiling() and floor().
|
| (And the ease that these mistakes can happen is why such fundamental
| functions should be in the standard library, no matter how easy they are
| to implement.)

I'll let Paul say whether is was a typo, due to answering too quickly, or a 
logic error, but I suspect the former.  *Any* expression can be mistyped.

tjr








More information about the Python-list mailing list