On Thu, Jan 8, 2015 at 7:07 PM, Chris Angelico <ros...@gmail.com> wrote: > On Fri, Jan 9, 2015 at 12:46 PM, Steven D'Aprano >> The fallback rule I use when float('nan') fails is >> >> INF = 1e3000 # Hopefully, this should overflow to INF. >> NAN = INF-INF # And this hopefully will give a NaN. > > The first question is "will 1eN overflow to inf?". I'm fairly sure > Python guarantees that an unrepresentable float constant will be > treated as infinity, so all you have to do is crank up the exponent > any time you suspect it'll be representable.
Or to never have to worry about it: INF = 1e400 while not math.isinf(INF): INF *= INF -- https://mail.python.org/mailman/listinfo/python-list