Surprise with special floating point values

P

prouleau001

Hi all,

While trying to use simplejson under Python 2.4.3 I have been
investigating the handling of special floating point values and found
that both Python 2.4 and 2.5 return False when comparing a NaN with
itself. Although surprising, I imagine it could also be correct since
NaN is not a number. But is it correct?

Notice the result of comparing c with itself in the following Python
2.5 session (it works the same on Python 2.4.3) under Win32::

Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
Thanks,
 
P

prouleau001

Hi all,

While trying to use simplejson under Python 2.4.3 I have been
investigating the handling of special floating point values and found
that both Python 2.4 and 2.5 return False when comparing a NaN with
itself. Although surprising, I imagine it could also be correct since
NaN is not a number. But is it correct?

And of course it is correct... As NaN does not compare with itself in
floating point: http://en.wikipedia.org/wiki/NaN

Should have read it earlier...

 
F

Fredrik Lundh

While trying to use simplejson under Python 2.4.3 I have been
investigating the handling of special floating point values

note that JSON doesn't support non-numeric floating point values, as can
be seen by the "number" syntax description on this page:

http://www.json.org/

(and as I pointed out in another thread on this topic, Python relies on
the C library for serialization of floats, so non-numeric floating point
values aren't portable between Python versions either).

</F>
 
P

prouleau001

be seen by the "number" syntax description on this page:

http://www.json.org/

(and as I pointed out in another thread on this topic, Python relies on
the C library for serialization of floats, so non-numeric floating point
values aren't portable between Python versions either).

</F>

That's true, but I ran into a problem with simplejson under Python
2.4.3 on Win32, where it fails to serialize 1.0 properly (and I
reported the problem to its author, and the fact that it works fine
under Python 2.5). There is another thread (Inconsistency producing
constant for float "infinity") that talks about differences between
Python 2.5 and earlier versions regarding treatment of non-numeric
floating point values. So, while investigating the simplejson problem,
I though I had found a problem with the handling of NaN (which
obviously is not the case).

- Pierre R.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,150
Members
46,697
Latest member
AugustNabo

Latest Threads

Top