Eval of expr with 'or' and 'and' within

Steven D'Aprano steve+comp.lang.python at pearwood.info
Fri Jun 14 21:34:24 EDT 2013


On Sat, 15 Jun 2013 00:09:31 +0100, Nobody wrote:

> On Sat, 15 Jun 2013 03:56:28 +1000, Chris Angelico wrote:
> 
>> With a few random oddities:
>> 
>>>>> bool(float("nan"))
>> True
>> 
>> I somehow expected NaN to be false. Maybe that's just my expectations
>> that are wrong, though.
> 
> In general, you should expect the behaviour of NaN to be the opposite of
> what you expect.

... even taking that into account! *wink*


Everyone is aware that there is more than one NAN, right? If my 
calculations are correct, there are 9007199254740992 distinct float NANs 
in Python (although there is no direct way of distinguishing them). Half 
have the sign bit set, half do not; half are quiet NANs and half are 
signalling NANs. It would be too easy if "sign bit set" meant signalling, 
so in fact there are four equal-numbered groups of NANs, 2251799813685248 
each of:

+quiet
+signalling
-quiet
-signalling

where the - sign should be interpreted as "sign bit is set" rather than 
"negative", and + sign as "sign bit not set".

They differ according to their bit-pattern, or payload. Some systems 
actually give standard meanings to different bit patterns, e.g. in the 
old SANE (Standard Apple Numerics Environment) system, different NANs 
were produced according to different kinds of errors, e.g:

Payload  Description
=======  ==========================================
1        Invalid sqrt
2        Invalid addition, e.g. +INF + -INF
3        Invalid division, e.g. 0/0
17       Convert invalid string
21       Attempt to create NAN with 0 as payload

etc.

(Assigning meaning to the payload is optional, according to the IEEE 754 
standard, if I recall correctly.)



-- 
Steven



More information about the Python-list mailing list