[New-bugs-announce] [issue18842] Add float.is_finite is_nan is_infinite to match Decimal methods
report at bugs.python.org
Mon Aug 26 17:59:17 CEST 2013
New submission from Steven D'Aprano:
On issue 15544 Mark Dickinson suggested adding methods to float to match methods on Decimal, giving type-agnostic ways of testing real numbers that don't rely on converting to float. I don't see any sign that Mark raised a feature request, so I'm taking the liberty of doing so myself.
Note that the math.is* functions convert to float first, which means that they behave differently. Example: math.isnan(Decimal('sNAN')) raises ValueError, rather than returning True.
would mirror the spelling of Decimal methods, rather than the math module. As float doesn't support signalling NANs, there probably isn't any need to include is_snan and is_qnan.
For what it's worth, I have code that would use this. I currently write something like:
if isinstance(x, Decimal) and x.is_nan() or math.isnan(x): ...
in order to prevent triggering the ValueError on signalling NANs.
title: Add float.is_finite is_nan is_infinite to match Decimal methods
versions: Python 3.4
Python tracker <report at bugs.python.org>
More information about the New-bugs-announce