where in Nan defined
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Thu Jan 8 20:46:27 EST 2015
Chris Angelico wrote:
> On Fri, Jan 9, 2015 at 1:50 AM, Jussi Piitulainen
> <jpiitula at ling.helsinki.fi> wrote:
>> >>> 0*1e400
>> nan
>
> Nice, that's shorter than mine.
o_O
Is that really the sort of thing you should be revealing here?
Oh wait, you're talking about code...
I'm not entirely sure, but I suspect that 0*1e400 may not be quite as
portable as your inf-inf. By the rules of IEEE-754 arithmetic, inf-inf has
to return a NAN, but if your floats have sufficient precision available to
represent 1e400, 0*1e400 might return 0.
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.
--
Steven
More information about the Python-list
mailing list