Arbitrary precision integer arithmetic: ceiling?
dickinsm at gmail.com
Sun Mar 9 03:11:24 CET 2008
On Mar 8, 8:48 pm, Steven D'Aprano <st... at REMOVE-THIS-
> 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
> >>> a, b = -101.0, 10.0
> >>> -(-a)//b # should be -10.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)
More information about the Python-list