Re: Rounding up to the nearest exact logarithmic decade

2006-02-28 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: > BTW, are the python-dev guys aware that 10 ** -1 = 0.10001 ? http://docs.python.org/tut/node16.html -- http://mail.python.org/mailman/listinfo/python-list

Re: Rounding up to the nearest exact logarithmic decade

2006-02-28 Thread Grant Edwards
On 2006-02-28, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > I like Fredrik's solution. If for some reason you are afraid of > logarithms, you could also do: > x = 4978 decades = [10 ** n for n in xrange(-1,8)] import itertools itertools.ifilter(lambda decade: x < decade, deca

Re: Rounding up to the nearest exact logarithmic decade

2006-02-28 Thread johnzenger
I like Fredrik's solution. If for some reason you are afraid of logarithms, you could also do: >>> x = 4978 >>> decades = [10 ** n for n in xrange(-1,8)] >>> import itertools >>> itertools.ifilter(lambda decade: x < decade, decades).next() 1 BTW, are the python-dev guys aware that 10 ** -1 =

Re: Rounding up to the nearest exact logarithmic decade

2006-02-28 Thread Grant Edwards
On 2006-02-28, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > Quoting Derek Basch <[EMAIL PROTECTED]>: > >> Given a value (x) that is within the range (1e-1, 1e7) how do I round >> (x) up to the closest exact logarithmic decade? For instance: > > How about this: > > def roundup(x): > if x < 1:

Re: Rounding up to the nearest exact logarithmic decade

2006-02-28 Thread Derek Basch
Thanks effbot. I knew their had to be something buried in the math module that could help. ceil() it is! -- http://mail.python.org/mailman/listinfo/python-list

Re: Rounding up to the nearest exact logarithmic decade

2006-02-28 Thread Felipe Almeida Lessa
Em Ter, 2006-02-28 às 17:47 -0500, [EMAIL PROTECTED] escreveu: > Quoting Derek Basch <[EMAIL PROTECTED]>: > > > Given a value (x) that is within the range (1e-1, 1e7) how do I round > > (x) up to the closest exact logarithmic decade? For instance: > > How about this: > > def roundup(x): > if

Re: Rounding up to the nearest exact logarithmic decade

2006-02-28 Thread jao
Quoting Derek Basch <[EMAIL PROTECTED]>: > Given a value (x) that is within the range (1e-1, 1e7) how do I round > (x) up to the closest exact logarithmic decade? For instance: How about this: def roundup(x): if x < 1: return 1 else: return '1' + ('0' * len(str(int(x

Re: Rounding up to the nearest exact logarithmic decade

2006-02-28 Thread Fredrik Lundh
Derek Basch wrote: > Given a value (x) that is within the range (1e-1, 1e7) how do I round > (x) up to the closest exact logarithmic decade? For instance: > > 10**3 = 1000 > x = 4978 > 10**4 = 1 > x = 1 how about >>> import math >>> def roundup(x): ...return 10**math.ceil

Rounding up to the nearest exact logarithmic decade

2006-02-28 Thread Derek Basch
Given a value (x) that is within the range (1e-1, 1e7) how do I round (x) up to the closest exact logarithmic decade? For instance: 10**3 = 1000 x = 4978 10**4 = 1 x = 1 Thanks Everyone! Derek Basch -- http://mail.python.org/mailman/listinfo/python-list