Re: Really basic problem

2007-10-10 Thread Ricardo Aráoz
tomamil wrote: > i know this example is stupid and useless, but that's not the answer > to my question. > here it goes: > > status = 0.0 > for i in range(10): >status = status + 0.1 > >if status == 0.1: >print status >elif status == 0.2: >print status >elif status

Re: Really basic problem

2007-10-10 Thread Dan Stromberg
On Mon, 08 Oct 2007 12:23:27 +0200, A.T.Hofkamp wrote: > On 2007-10-08, Andreas Tawn <[EMAIL PROTECTED]> wrote: >>> i know this example is stupid and useless, but that's not the answer >>> to my question. >>> here it goes: >>> >> You've just discovered the joys of floating point number comparison

Re: Really basic problem

2007-10-08 Thread Diez B. Roggisch
Zentrader wrote: > You can use Python's decimal class if floating point arithmetic is not > exact enough This is a misleading statement. While it's true that decimal can be more precise in the sense that smaller fractions are representable, the underlying problem of certain values not being repre

Re: Really basic problem

2007-10-08 Thread Zentrader
You can use Python's decimal class if floating point arithmetic is not exact enough import decimal status = decimal.Decimal( 0 ) for i in range(10): status += decimal.Decimal( "0.1" ) if status == decimal.Decimal( "0.1" ): print status elif status == decimal.Decimal( "0.2" ):

RE: Really basic problem

2007-10-08 Thread Andreas Tawn
> > I guess this means that Python has some concept of "close > enough", but > > I'll have to defer to someone more knowledgeable to explain that. > > No, not really, except in the sense that any floating point > calculation > will be necessarily imprecise in that sense. [snip] > So typing 0.3

Re: Really basic problem

2007-10-08 Thread tomamil
thanks you all guys for your help, it's really appreciated... m. -- http://mail.python.org/mailman/listinfo/python-list

Re: Really basic problem

2007-10-08 Thread Steven D'Aprano
On Mon, 08 Oct 2007 12:09:28 +0200, Andreas Tawn wrote: > The issue is that 0.1 etc don't have an exact representation as floating > point. > > Interestingly: > 0.10001 == 0.1 > True 0.30004 == 0.3 > False > > I guess this means that Python has some concept of

Re: Really basic problem

2007-10-08 Thread A.T.Hofkamp
On 2007-10-08, Andreas Tawn <[EMAIL PROTECTED]> wrote: >> i know this example is stupid and useless, but that's not the answer >> to my question. >> here it goes: >> > You've just discovered the joys of floating point number comparisons. > > Consider this snippet: > > status = 0.0 > print (repr(st

RE: Really basic problem

2007-10-08 Thread Andreas Tawn
> i know this example is stupid and useless, but that's not the answer > to my question. > here it goes: > > status = 0.0 > for i in range(10): >status = status + 0.1 > >if status == 0.1: >print status >elif status == 0.2: >print status >elif status == 0.3: >

Re: Really basic problem

2007-10-08 Thread John Machin
On 8/10/2007 7:39 PM, tomamil wrote: > i know this example is stupid and useless, but that's not the answer > to my question. > here it goes: > > status = 0.0 > for i in range(10): >status = status + 0.1 > [snip] 0.1 can not be represented exactly as a binary floating-point number. to see wh