[issue4084] Decimal.max(NaN, x) gives incorrect results when x is finite and long

Mark Dickinson report at bugs.python.org
Thu Oct 9 10:43:17 CEST 2008


New submission from Mark Dickinson <dickinsm at 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 at bugs.python.org>
<http://bugs.python.org/issue4084>
_______________________________________


More information about the Python-bugs-list mailing list