where in Nan defined

Ian Kelly ian.g.kelly at gmail.com
Thu Jan 8 21:12:45 EST 2015


On Thu, Jan 8, 2015 at 7:07 PM, Chris Angelico <rosuav at 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



More information about the Python-list mailing list