pickle broken: can't handle NaN or Infinity under win32

Steven D'Aprano steve at REMOVETHIScyber.com.au
Thu Jun 23 06:34:36 EDT 2005


On Thu, 23 Jun 2005 00:11:20 -0400, Tim Peters wrote:

> Well, I try, Ivan.  But lest the point be missed <wink>, 754 doesn't
> _want_ +0 and -0 to act differently in "almost any" way.  The only
> good rationale I've seen for why it makes the distinction at all is in
> Kahan's paper "Branch Cuts for Complex
> Elementary Functions, or Much Ado About Nothing's Sign Bit".  There
> are examples in that where, when working with complex numbers, you can
> easily stumble into getting real-world dead-wrong results if there's
> only one flavor of 0.  And, of course, atan2 exists primarily to help
> convert complex numbers from rectangular to polar form.

It isn't necessary to look at complex numbers to see the difference
between positive and negative zero. Just look at a graph of y=1/x. In
particular, look at the behaviour of the graph around x=0. Now tell me
that the sign of zero doesn't make a difference.

Signed zeroes also preserve 1/(1/x) == x for all x, admittedly at the cost
of y==x iff 1/y == 1/x (which fails for y=-0 and x=+0). Technically, -0
and +0 are not the same (for some definition of "technically"); but
practicality beats purity and it is more useful to have -0==+0 than the
alternative.

> Odd bit o' trivia:  following "the rules" for signed zeroes in 754
> makes exponeniation c**n ambiguous, where c is a complex number with
> c.real == c.imag == 0.0 (but the zeroes may be signed), and n is a
> positive integer.  The signs on the zeroes coming out can depend on
> the exact order in which multiplications are performed, because the
> underlying multiplication isn't associative despite that it's exact. 

That's an implementation failure. Mathematically, the sign of 0**n should
depend only on whether n is odd or even. If c**n is ambiguous, then that's
a bug in the implementation, not the standard.

> I stumbled into this in the 80's when KSR's Fortran compiler failed a
> federal conformance test, precisely because the test did atan2 on the
> components of an all-zero complex raised to an integer power, and I
> had written one of the few 754-conforming libms at the time.  They
> wanted 0, while my atan2 dutifully returned -pi.  I haven't had much
> personal love for 754 esoterica since then ...

Sounds to me that the Feds wanted something broken and you gave them
something that was working. No wonder they failed you :-)

-- 
Steven.





More information about the Python-list mailing list