Re: why do I get this behavior from a while loop?

2009-11-28 Thread Tim Roberts
"S. Chris Colbert" wrote: > >What a newbie mistake for me to make. Don't feel too badly about it. Even very experienced programmers get bitten by this issue. Until someone points it out, it's certainly not obvious. -- Tim Roberts, t...@probo.com Providenza & Boekelheide, Inc. -- http://mail.p

Re: why do I get this behavior from a while loop?

2009-11-27 Thread S. Chris Colbert
What a newbie mistake for me to make. I appreciate the replies everyone! Cheers, Chris > On Fri, 27 Nov 2009 17:06:44 +0100, S. Chris Colbert wrote: > > I would think that second loop should terminate at 9.9, no? > > > > I am missing something fundamental? > > "What Every Computer Scientist Sh

Re: why do I get this behavior from a while loop?

2009-11-27 Thread Steven D'Aprano
On Fri, 27 Nov 2009 17:06:44 +0100, S. Chris Colbert wrote: > I would think that second loop should terminate at 9.9, no? > > I am missing something fundamental? "What Every Computer Scientist Should Know About Floating Point" http://docs.sun.com/source/806-3568/ncg_goldberg.html -- Steven

Re: why do I get this behavior from a while loop?

2009-11-27 Thread Carsten Haese
S. Chris Colbert wrote: > In [15]: t = 0. > > In [16]: time = 10. > > In [17]: while t < time: >: print t >: t += 0.1 >: >: > 0.0 > 0.1 > 0.2 > 0.3

Re: why do I get this behavior from a while loop?

2009-11-27 Thread Tim Wintle
On Fri, 2009-11-27 at 17:06 +0100, S. Chris Colbert wrote: > This seems strange to me, but perhaps I am just missing something: > I would think that second loop should terminate at 9.9, no? > > I am missing something fundamental? Floating points variables ... http://en.wikipedia.org/wiki/Floati

Re: why do I get this behavior from a while loop?

2009-11-27 Thread Paul Rudin
"S. Chris Colbert" writes: >: print t Try replacing with: print "%0.20f" % t The thing you're missing is that floating point arithmetic isn't (in general) exact - but when it's printed it's rounded. -- http://mail.python.org/mailman/listinfo/python-list

Re: why do I get this behavior from a while loop?

2009-11-27 Thread Diez B. Roggisch
S. Chris Colbert schrieb: This seems strange to me, but perhaps I am just missing something: In [12]: t = 0. In [13]: time = 10. In [14]: while t < time: : print t : t += 1. : : 0.0 1.0

why do I get this behavior from a while loop?

2009-11-27 Thread S. Chris Colbert
This seems strange to me, but perhaps I am just missing something: In [12]: t = 0. In [13]: time = 10. In [14]: while t < time: : print t : t += 1. : : 0.0 1.0 2.0