struct doesn't handle NaN values?

Grant Edwards grante at visi.com
Thu May 13 22:26:58 EDT 2004


In article <mailman.539.1084498522.25742.python-list at python.org>, Jeff Epler wrote:
>
>> In order to provide robust translation between native and IEEE
>> floating point formats, Python is going to have to know what
>> the native format is.
> 
> No, it merely needs to use ldexp() with the proper values.

If you don't know what the native representations for NaN and
infinity are, how do you know what to pass to ldexp() when the
conversion routine has been passed an IEEE NaN/Inf and needs to
create a native one?  

If you do pass ldexp() the proper exponent for a native NaN,
are you sure it will work?  I would expect that doing so would
be an error.

How do you detect a native NaN using ldexp() or frexp() or some
other standard C library function?

> Did you try reading what Python actually does? 

Yes.

> See Objects/floatobject.c's function family _PyFloat_{Unpack,Pack}{4,8}

I did.  It states quite clearly in floatobject.h:

 Bug:  What this does is undefined if x is a NaN or infinity.

 Bug:  What this does is undefined if the string represents a NaN or infinity.

I'd like to fix those Bugs so that the conversions between
native NaN/Inf and IEEE NaN/Inf works.  I don't see how you can
get around the requirement for knowledge about the native
representation of NaNs and Infinities.
 
-- 
Grant Edwards                   grante             Yow!  I'm in ATLANTIC CITY
                                  at               riding in a comfortable
                               visi.com            ROLLING CHAIR...



More information about the Python-list mailing list