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.max(NaN, x) gives incorrect results when x is finite and long #48334

Closed
mdickinson opened this issue Oct 9, 2008 · 6 comments
Closed
Assignees
Labels
type-bug An unexpected behavior, bug, or error

Comments

@mdickinson
Copy link
Member

BPO 4084
Nosy @loewis, @facundobatista, @mdickinson
Files
  • decimal_maxbug.patch: Fix for this issue
  • 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 = 'https://github.com/mdickinson'
    closed_at = <Date 2008-12-11.09:25:20.564>
    created_at = <Date 2008-10-09.08:43:16.990>
    labels = ['type-bug']
    title = 'Decimal.max(NaN, x) gives incorrect results when x is finite and long'
    updated_at = <Date 2008-12-11.09:25:20.562>
    user = 'https://github.com/mdickinson'

    bugs.python.org fields:

    activity = <Date 2008-12-11.09:25:20.562>
    actor = 'mark.dickinson'
    assignee = 'mark.dickinson'
    closed = True
    closed_date = <Date 2008-12-11.09:25:20.564>
    closer = 'mark.dickinson'
    components = []
    creation = <Date 2008-10-09.08:43:16.990>
    creator = 'mark.dickinson'
    dependencies = []
    files = ['11753']
    hgrepos = []
    issue_num = 4084
    keywords = ['patch']
    message_count = 6.0
    messages = ['74557', '77518', '77589', '77594', '77600', '77601']
    nosy_count = 3.0
    nosy_names = ['loewis', 'facundobatista', 'mark.dickinson']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = None
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue4084'
    versions = ['Python 2.6', 'Python 3.0']

    @mdickinson
    Copy link
    Member Author

    Here's a snippet from Python 2.6:

    >>> from decimal import Decimal, getcontext
    >>> getcontext().prec = 3
    >>> Decimal('NaN').max(Decimal('1234'))
    Decimal('sNaN234')

    The result here should be Decimal('1.23E+3')---the specification says that
    the result of comparing a quiet NaN with a finite value should be that
    finite value, rounded according to the context.

    This also affects min, max_mag and min_mag.

    The cause is that non-NaNs are incorrectly being passed to the _fix_nan
    method. The attached patch fixes this, and adds new testcases to
    extra.decTest to stop it happening again.

    It would be good to get this fix into 3.0, if possible. I think it should
    also be backported to 2.5.3.

    @mdickinson mdickinson added the type-bug An unexpected behavior, bug, or error label Oct 9, 2008
    @loewis
    Copy link
    Mannequin

    loewis mannequin commented Dec 10, 2008

    Unless Facundo or some of the other decimal contributors reviews and
    applies this patch really quickly, it is out of scope for 2.5.3.

    @facundobatista
    Copy link
    Member

    Commited in trunk and Py3, thanks Mark!

    Please, could you commit it in 2.5? The only change I've made in the
    patch is adding the issue number to Misc/NEWS, the rest is ok.

    After that, just close this.

    Thanks again!

    @loewis
    Copy link
    Mannequin

    loewis mannequin commented Dec 11, 2008

    Mark, if you want to backport this, please go ahead. If want me to,
    assign to me.

    @loewis loewis mannequin added the release-blocker label Dec 11, 2008
    @loewis loewis mannequin assigned mdickinson and unassigned facundobatista Dec 11, 2008
    @mdickinson
    Copy link
    Member Author

    Committed, r67699. Thanks!

    Leaving open because I still need to merge this to the 3.0 and 2.6
    maintenance branches.

    @mdickinson
    Copy link
    Member Author

    Merged to 2.6 and 3.0 maintenance branches (r67700, r67701).

    @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
    type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants