Bugs item #1650053, was opened at 2007-02-01 13:20
Message generated for change (Comment added) made by rhettinger
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1650053&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Library
Group: Python 2.5
>Status: Closed
>Resolution: Wont Fix
Priority: 5
Private: No
Submitted By: Brian Sutherland (jinty_)
>Assigned to: Nobody/Anonymous (nobody)
Summary: decimals compare badly to floats

Initial Comment:
This behaviour is so unexpected that I'm pretty sure it's a bug. If decimals 
can't be compared to floats, at least it should error.

Found in python2.4 and 2.5 by at least 2 people:

Python 2.5 (release25-maint, Dec  9 2006, 14:35:53)
[GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-20)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from decimal import Decimal
>>> 1172837167.27 > Decimal("1172837136.0800")
False
>>> 1172837167.27 > Decimal("1")
False


----------------------------------------------------------------------

>Comment By: Raymond Hettinger (rhettinger)
Date: 2007-02-12 02:40

Message:
Logged In: YES 
user_id=80475
Originator: NO

The __cmp__() method decimal.py is doing the right thing and returning
NotImplemented.

The odd result you're seeing is just Python's normal way of handling
things it doesn't know how to compare.  You get the same results by
comparing floats to strings:

>>> 1172837167.27 > "1172837136.0800"
False
>>> 1172837167.27 > "1"
False

I don't see a way to change this behavior without making deep incompatible
changes to Python.

If someone sees a way out, feel free to re-open this bug.

----------------------------------------------------------------------

Comment By: Raymond Hettinger (rhettinger)
Date: 2007-02-01 15:24

Message:
Logged In: YES 
user_id=80475
Originator: NO

It was intended that Decimals not be compared to floats, but I think we
can do better than returning a useless result

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1650053&group_id=5470
_______________________________________________
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to