Comparing float and decimal
timr at probo.com
Thu Sep 25 09:55:52 CEST 2008
Marc 'BlackJack' Rintsch <bj_666 at gmx.net> wrote:
>On Tue, 23 Sep 2008 07:08:07 -0700, Michael Palmer wrote:
>>> > This seems to break the rule that if A is equal to B and B is equal
>>> > to C then A is equal to C.
>>> I don't see why transitivity should apply to Python objects in general.
>> Well, for numbers it surely would be a nice touch, wouldn't it. May be
>> the reason for Decimal to accept float arguments is that irrational
>> numbers or very long rational numbers cannot be converted to a Decimal
>> without rounding error, and Decimal doesn't want any part of it. Seems
>> pointless to me, though.
>Is 0.1 a very long number? Would you expect ``0.1 == Decimal('0.1')`` to
>be `True` or `False` given that 0.1 actually is
>In : '%.50f' % 0.1
Actually, it's not. Your C run-time library is generating random digits
after it runs out of useful information (which is the first 16 or 17
digits). 0.1 in an IEEE 784 double is this:
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.
More information about the Python-list