Re: Integer Division

2009-06-19 Thread Terry Reedy
Anjanesh Lekshminarayanan wrote: a = 1 b = 25 a / b 0 float(a) / b 0.040001 from __future__ import division a = 1 b = 25 a / b 0.040001 In what simple way can I get just 0.04 ? Short answer: use 3.1: >>> 1//25 0 >>> 1/25 0.04 ;-) But you should really try to unde

Re: Integer Division

2009-06-19 Thread Grant Edwards
On 2009-06-19, Anjanesh Lekshminarayanan wrote: a = 1 b = 25 a / b > 0 float(a) / b > 0.040001 > from __future__ import division a = 1 b = 25 a / b > 0.040001 > > In what simple way can I get just 0.04 ? You can't. There _

Re: Integer Division

2009-06-19 Thread Dave Angel
Anjanesh Lekshminarayanan wrote: a = 1 b = 25 a / b 0 float(a) / b 0.040001 from __future__ import division a = 1 b = 25 a / b 0.040001 In what simple way can I get just 0.04 ? Your subject line says "Integer Division" but

Re: Integer Division

2009-06-19 Thread Piet van Oostrum
> Anjanesh Lekshminarayanan (AL) escribió: > a = 1 > b = 25 > a / b >AL> 0 > float(a) / b >AL> 0.040001 > > from __future__ import division > a = 1 > b = 25 > a / b >AL> 0.040001 > >AL> In what simple way can I get just 0.04

Re: Integer Division

2009-06-19 Thread Mark Dickinson
On Jun 19, 8:22 am, Anjanesh Lekshminarayanan wrote: > >>> a = 1 > >>> b = 25 > >>> a / b > 0 > >>> float(a) / b > > 0.040001 Python typically stores floats in binary, not decimal. The value 0.04 isn't exactly representable in binary, so the division float(1)/25 can't produce 0.04:

Re: Integer Division

2009-06-19 Thread Chris Rebert
On Fri, Jun 19, 2009 at 12:22 AM, Anjanesh Lekshminarayanan wrote: a = 1 b = 25 a / b > 0 float(a) / b > 0.040001 > from __future__ import division a = 1 b = 25 a / b > 0.040001 > > In what simple way can I get just 0.04 ? N

Re: Integer division

2007-06-07 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, Dan Bishop wrote: > On Jun 7, 8:30 pm, Some Other Guy <[EMAIL PROTECTED]> wrote: >> Since this just involves doubling you can avoid multiplying altogether >> and just use this: >> >> def rounddiv(a,b): >> return int((a+a+b)/(b+b)) >> >> That's 3 integer adds and 1 integer

Re: Integer division

2007-06-07 Thread Terry Reedy
"Some Other Guy" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] | [EMAIL PROTECTED] wrote: | | > Hello all, | > I have two integers and I want to divide one by another, and want to | > get an integer result which is the higher side whenever the result is | > a fraction. | > 3/2 =>

Re: Integer division

2007-06-07 Thread Dan Bishop
On Jun 7, 8:30 pm, Some Other Guy <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] wrote: > > Hello all, > > I have two integers and I want to divide one by another, and want to > > get an integer result which is the higher side whenever the result is > > a fraction. > > 3/2 => 1 # Usual behavior >

Re: Integer division

2007-06-07 Thread Terry Reedy
"Sion Arrowsmith" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] | [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: | > 3/2 => 1 # Usual behavior | > some_func(3, 2) => 2 # Wanted | | def some_func(a, b): |return -(-a/b) | | And people complain about Python's behaviour regarding divi

Re: Integer division

2007-06-07 Thread Sion Arrowsmith
Hamish Moffatt <[EMAIL PROTECTED]> wrote: >[EMAIL PROTECTED] wrote: > def div_ceil(a, b): >> ... if a%b: >> ... return ((a/b)+1) >> ... else: >> ... return (a/b) > >Yes, although it's not as short or as fast (probably as my version): > >def div_ceil(a, b): > return

Re: Integer division

2007-06-07 Thread Hamish Moffatt
[EMAIL PROTECTED] wrote: > On Jun 7, 2:15 pm, Hamish Moffatt <[EMAIL PROTECTED]> wrote: >> [EMAIL PROTECTED] wrote: >>> Hello all, >>> I have two integers and I want to divide one by another, and want to >>> get an integer result which is the higher side whenever the result is >>> a fraction. >>>

Re: Integer division

2007-06-07 Thread Sion Arrowsmith
[EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > 3/2 => 1 # Usual behavior > some_func(3, 2) => 2 # Wanted def some_func(a, b): return -(-a/b) And people complain about Python's behaviour regarding division of negative integers. -- \S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/

Re: Integer division

2007-06-07 Thread [EMAIL PROTECTED]
On Jun 7, 2:15 pm, Hamish Moffatt <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] wrote: > > Hello all, > > I have two integers and I want to divide one by another, and want to > > get an integer result which is the higher side whenever the result is > > a fraction. > > 3/2 => 1 # Usual behavior >

Re: Integer division

2007-06-07 Thread Hamish Moffatt
[EMAIL PROTECTED] wrote: > Hello all, > I have two integers and I want to divide one by another, and want to > get an integer result which is the higher side whenever the result is > a fraction. > 3/2 => 1 # Usual behavior > some_func(3, 2) => 2 # Wanted > > Any easier solution other than int(m