homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: decimal.py: TypeError precedence in fma()
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.3, Python 3.4
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: rhettinger Nosy List: mark.dickinson, python-dev, rhettinger, skrah
Priority: normal Keywords:

Created on 2011年05月15日 07:50 by skrah, last changed 2022年04月11日 14:57 by admin. This issue is now closed.

Messages (6)
msg136014 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2011年05月15日 07:50
Hi, I think that TypeError should take precedence over InvalidOperation
in these two cases:
>>> Decimal('Infinity').fma(Decimal('0'), (3.91224318126786e+19+0j))
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
 File "/usr/local/lib/python3.2/decimal.py", line 1879, in fma
 'INF * 0 in fma')
 File "/usr/local/lib/python3.2/decimal.py", line 3926, in _raise_error
 raise error(explanation)
decimal.InvalidOperation: INF * 0 in fma
>>> 
>>> Decimal('1').fma(Decimal('snan'), 1.2222222222)
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
 File "/usr/local/lib/python3.2/decimal.py", line 1871, in fma
 return context._raise_error(InvalidOperation, 'sNaN', other)
 File "/usr/local/lib/python3.2/decimal.py", line 3926, in _raise_error
 raise error(explanation)
decimal.InvalidOperation: sNaN
>>>
msg136017 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2011年05月15日 07:59
Yes, I agree. Do you have a patch? I guess the only mildly tricky part here is making sure that the patch doesn't cause fma(2, 3, snan) (for example) to raise.
msg136018 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2011年05月15日 08:01
> cause fma(2, 3, snan) ...
Gah! That was nonsense. Please ignore.
msg136024 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2011年05月15日 08:29
Ok, I'll write a patch.
msg136516 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2011年05月22日 11:53
New changeset 825b4278a055 by Mark Dickinson in branch 'default':
Issue #12079: Decimal(0).fma(Decimal('inf'), 'not a number') should give a TypeError, not a Decimal.InvalidOperation
http://hg.python.org/cpython/rev/825b4278a055 
msg136517 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2011年05月22日 11:56
It turns out that this is as simple as moving the _convert_other call to the top of the Decimal.fma method. (For some reason I was confusing this with the subtleties involved in making sure that an InvalidOperation arising from the multiplication part of the fma takes precedence over an InvalidOperation coming from a signalling nan in the addend.)
Fixed.
History
Date User Action Args
2022年04月11日 14:57:17adminsetgithub: 56288
2011年05月22日 11:56:22mark.dickinsonsetstatus: open -> closed
resolution: fixed
messages: + msg136517
2011年05月22日 11:53:36python-devsetnosy: + python-dev
messages: + msg136516
2011年05月16日 05:42:13rhettingersetassignee: rhettinger
2011年05月15日 08:29:43skrahsetmessages: + msg136024
2011年05月15日 08:01:43mark.dickinsonsetmessages: + msg136018
2011年05月15日 07:59:13mark.dickinsonsetmessages: + msg136017
2011年05月15日 07:50:05skrahcreate

AltStyle によって変換されたページ (->オリジナル) /