Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

decimal.Decimal greater than/less than sometimes gives wrong answers when comparing to floats. #51572

Closed
adamtj mannequin opened this issue Nov 14, 2009 · 3 comments
Closed
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@adamtj
Copy link
Mannequin

adamtj mannequin commented Nov 14, 2009

BPO 7323
Nosy @mdickinson
Superseder
  • bpo-2531: float compared to decimal is silently incorrect.
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2009-11-14.22:20:49.225>
    created_at = <Date 2009-11-14.18:39:19.397>
    labels = ['type-bug', 'library']
    title = 'decimal.Decimal greater than/less than sometimes gives wrong answers when comparing to floats.'
    updated_at = <Date 2009-11-14.22:39:16.972>
    user = 'https://bugs.python.org/adamtj'

    bugs.python.org fields:

    activity = <Date 2009-11-14.22:39:16.972>
    actor = 'mark.dickinson'
    assignee = 'none'
    closed = True
    closed_date = <Date 2009-11-14.22:20:49.225>
    closer = 'mark.dickinson'
    components = ['Library (Lib)']
    creation = <Date 2009-11-14.18:39:19.397>
    creator = 'adamtj'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 7323
    keywords = []
    message_count = 3.0
    messages = ['95248', '95262', '95264']
    nosy_count = 2.0
    nosy_names = ['mark.dickinson', 'adamtj']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = None
    status = 'closed'
    superseder = '2531'
    type = 'behavior'
    url = 'https://bugs.python.org/issue7323'
    versions = ['Python 2.6', 'Python 2.5', 'Python 2.4']

    @adamtj
    Copy link
    Mannequin Author

    adamtj mannequin commented Nov 14, 2009

    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

    @adamtj adamtj mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Nov 14, 2009
    @mdickinson
    Copy link
    Member

    Unfortunately there's no easy way to fix this in 2.x, where any object is
    supposed to be comparable with any other. See bpo-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 bpo-2531. bpo-2531 is also closed, but you
    should feel free to add to the discussion there.

    @mdickinson
    Copy link
    Member

    I've re-opened bpo-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.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant