Message196219
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. |
|
Date |
User |
Action |
Args |
2013-08-26 15:59:17 | steven.daprano | set | recipients:
+ steven.daprano |
2013-08-26 15:59:17 | steven.daprano | set | messageid: <1377532757.24.0.123652540945.issue18842@psf.upfronthosting.co.za> |
2013-08-26 15:59:17 | steven.daprano | link | issue18842 messages |
2013-08-26 15:59:17 | steven.daprano | create | |
|