classification
Title: decimal.Decimal greater than/less than sometimes gives wrong answers when comparing to floats.
Type: behavior Stage:
Components: Library (Lib) Versions: Python 2.4, Python 2.6, Python 2.5
process
Status: closed Resolution: duplicate
Dependencies: Superseder: float compared to decimal is silently incorrect.
View: 2531
Assigned To: Nosy List: adamtj, mark.dickinson
Priority: normal Keywords:

Created on 2009-11-14 18:39 by adamtj, last changed 2009-11-14 22:39 by mark.dickinson. This issue is now closed.

Messages (3)
msg95248 - (view) Author: Adam Tomjack (adamtj) Date: 2009-11-14 18:39
These should all return False, or some of them should raise exceptions:

Python 2.6.2 (release26-maint, Apr 19 2009, 01:58:18)
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import decimal
>>> decimal.Decimal('0') > 0
False
>>> decimal.Decimal('0') < 0
False
>>> decimal.Decimal('0') > 0.0
True
>>> decimal.Decimal('0') < 0.0
False
>>> 0.0 > decimal.Decimal('0')
False
>>> 0.0 < decimal.Decimal('0')
True
>>> 0.0 < decimal.Decimal('0.0')
True
>>> decimal.Decimal('0') > decimal.Decimal('0')
False
msg95262 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2009-11-14 22:20
Unfortunately there's no easy way to fix this in 2.x, where any object is 
supposed to be comparable with any other.  See issue 2531 for a previous 
discussion.  It's fixed in 3.x:  there a comparison (other than ==, !=) 
between a float and a Decimal does raise an exception.

Closing as a duplicate of issue 2531.  Issue 2531 is also closed, but you 
should feel free to add to the discussion there.
msg95264 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2009-11-14 22:39
I've re-opened issue 2531:  some recent changes (in particular, the 
backport of the 3.x float <-> string conversions to 2.x) may make 
previously rejected solutions viable again.
History
Date User Action Args
2009-11-14 22:39:16mark.dickinsonsetmessages: + msg95264
2009-11-14 22:20:49mark.dickinsonsetstatus: open -> closed
resolution: duplicate
superseder: float compared to decimal is silently incorrect.
messages: + msg95262
2009-11-14 18:48:06r.david.murraysetnosy: + mark.dickinson
2009-11-14 18:39:33adamtjsettype: behavior
2009-11-14 18:39:19adamtjcreate