Arbitrary precision integer arithmetic: ceiling?
Mark Dickinson
dickinsm at gmail.com
Sat Mar 8 21:11:24 EST 2008
On Mar 8, 8:48 pm, Steven D'Aprano <st... at REMOVE-THIS-
cybersource.com.au> wrote:
> On Sat, 08 Mar 2008 17:09:11 -0800, Mark Dickinson wrote:
> > I prefer:
>
> > ceiling(a/b) = -(-a)//b
>
> Unfortunately it doesn't give the right answer.
>
> >>> a, b = 101.0, 10.0
> >>> -(-a)//b # should be 11.0
> 10.0
> >>> a, b = -101.0, 10.0
> >>> -(-a)//b # should be -10.0
>
> -11.0
>
> Looks like you've confused ceiling() and floor().
Whoops, you're right. No, I didn't confuse ceiling and floor;
I misplaced the parentheses. I meant to type:
ceiling(a/b) = -(-a//b)
Mark
More information about the Python-list
mailing list