On Mon, 30 May 2011 04:29:19 +0000, Chris Torek wrote: > In article <4de31635$0$29990$c3e8da3$54964...@news.astraweb.com>, Steven > D'Aprano <steve+comp.lang.pyt...@pearwood.info> wrote: >>That's also completely wrong. The correct way to test for a NAN is with >>the IEEE-mandated function isnan(). The NAN != NAN trick is exactly >>that, a trick, used by programmers when their language or compiler >>doesn't support isnan(). > > Perhaps it would be reasonable to be able to do: > > x.isnan() > > when x is a float.
Better than a float method is a function which takes any number as argument: >>> import math, fractions, decimal >>> math.isnan(fractions.Fraction(2, 3)) False >>> math.isnan(decimal.Decimal('nan')) True You can even handle complex NANs with the cmath module: >>> import cmath >>> cmath.isnan(complex(1, float('nan'))) True -- Steven -- http://mail.python.org/mailman/listinfo/python-list