struct doesn't handle NaN values?

John Roth newsgroups at jhrothjr.com
Thu May 13 21:38:31 EDT 2004


"Grant Edwards" <grante at visi.com> wrote in message
news:slrnca7slj.bsf.grante at grante.rivatek.com...
> On 2004-05-13, John Roth <newsgroups at jhrothjr.com> wrote:
>
> >> Which part of the C library is broken?
> >
> > Which C library?
>
> That's what I'm asked?  I was told the C library was broken. I
> wanted to know what C library.

The breakage has to do with the character values they
use to denote infinities and NaN, not (as far as
I know) with the detection of them. Whether they are
"broken" is a matter of interpretation, since the C standard
didn't specify what the library should expect and return
when converting from string to float and vice versa.
What is true is that they aren't consistent.
>
> > Python runs on 20 different systems, many of which have
> > multiple operating systems, each of which has its own C
> > library with its own problems. It's not even a standards
> > issue: the older standards didn't specify what the C library's
> > conversion routines should do.
>
> I presumed that struct was doing the conversion itself.  The
> doc specified IEEE format, it would have to do it's own
> conversion since it couldn't assume that the host used IEEE
> format, and as you say, there's no portable library support
> that can be relied upon.

I don't think so. I believe that the reference to IEEE means
that it generally expects bit compatible IEEE representations.
There may be differences, but I doubt if struct is aware of
them. As usual, the source would be definitive.

> > I referred you to PEP 754 for a reason. That PEP contains
> > a thorough discussion of the issues in the treatment of special
> > values in Python floating point.
> >
> > http://www.python.org/peps/pep-0754.html
> >
> > It also contains a reference to a module that handles
> > the matter.
>
> I read it.  It only handles double-precision values, and I'm
> working with single-precision values.

I expect it would be easy enough to convert. I just read
it, and it doesn't look at all complicated.

John Roth


>
> -- 
> Grant Edwards                   grante             Yow!  I just had my
entire
>                                   at               INTESTINAL TRACT coated
>                                visi.com            with TEFLON!





More information about the Python-list mailing list