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.

Author steven.daprano
Recipients steven.daprano
Date 2013-08-26.15:59:17
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1377532757.24.0.123652540945.issue18842@psf.upfronthosting.co.za>
In-reply-to
Content
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.

float.is_nan
float.is_infinity
float.is_finite

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.
History
Date User Action Args
2013-08-26 15:59:17steven.dapranosetrecipients: + steven.daprano
2013-08-26 15:59:17steven.dapranosetmessageid: <1377532757.24.0.123652540945.issue18842@psf.upfronthosting.co.za>
2013-08-26 15:59:17steven.dapranolinkissue18842 messages
2013-08-26 15:59:17steven.dapranocreate