struct doesn't handle NaN values?

Grant Edwards grante at visi.com
Thu May 13 17:28:37 EDT 2004


On 2004-05-13, John Roth <newsgroups at jhrothjr.com> wrote:

>> Perhaps I'm doing something wrong: the struct module docs say
>> it's IEE 754, but I can't figure out how to get it to handle
>> NaN values correctly (either packing or unpacking).

> I believe that struct uses the c library as is,

That's not what the docs say. The struct docs says it converts
between native Python values and IEEE 754.  If that's not the
case and it converts between Python float format and "native C
library" format, then the docs need to be changed [and I'll
need to write something that converts to/from IEEE 754 format.]

> like the float support in general. Unfortunately, that leaves
> everyone at the mercy of the rather inconsistent and
> ideosyncratic implementations of corner cases in existing c
> libraries.

But, my c library seems to handle it correctly:
  
 1) 0xffffffff is treated correctly as a NaN.
 2) NaN's are detected and converted to strings as 'nan'.

Which part of the C library is broken?

-- 
Grant Edwards                   grante             Yow!  AIEEEEE! I am having
                                  at               an UNDULATING EXPERIENCE!
                               visi.com            



More information about the Python-list mailing list