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
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
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
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" ):
> > 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
thanks you all guys for your help, it's really appreciated...
m.
--
http://mail.python.org/mailman/listinfo/python-list
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
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
> 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:
>
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
10 matches
Mail list logo