Mailing List Archive

[issue4084] Decimal.max(NaN, x) gives incorrect results when x is finite and long
New submission from Mark Dickinson <dickinsm@gmail.com>:

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.

----------
assignee: facundobatista
files: decimal_maxbug.patch
keywords: patch
messages: 74557
nosy: facundobatista, marketdickinson
priority: normal
severity: normal
status: open
title: Decimal.max(NaN, x) gives incorrect results when x is finite and long
type: behavior
versions: Python 2.5.3, Python 2.6, Python 2.7, Python 3.0
Added file: http://bugs.python.org/file11753/decimal_maxbug.patch

_______________________________________
Python tracker <report@bugs.python.org>
<http://bugs.python.org/issue4084>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com