-0.0 => -0.0
As far as I can tell, this causes no problems, since:
sign(-0.0) => zero
is(0.0=-0.0) => true
is(equal(0.0,-0.0)) => true
?equal(bfloat(0.0),bfloat(-0.0)) => true
is(-0.0 < 0.0) => false
( x[-0.0]:'n, x[0.0]:'p, x[-0.0] ) => p
{ 0.0, -0.0 } => {-0.0}
Although ?equal(0.0,-0.0) => false, I haven't been able to come up with a case where that causes problems. That is, in Maxima, there is no distinction other than the print representation.
So the only case that might be a problem is that string(0.0)#string(-0.0).
Hi Stavros,
Under some lisp implementations like SBCL that support negative zeros:
Also recall that CL allows, but doesn't require, support for negative zeros. So under some other implementations like CLISP,
%o8should be the same as%o7.Kris, thanks for checking. I should have mentioned in my original note that I was running on SBCL on Mac, but I don't know what version of Maxima (failure in basic bug reporting hygiene!). As I said, I didn't find any problems in SBCL, but we might want to add some test cases to ensure that all this works across implementations.
My current installation (5.49 on SBCL 2.6.0 on WIndows 11) actually gives {0.0,-0.0} => {0.0}, but I couldn't find any anomalies with set operations, where 0.0 is treated as equivalent to -0.0. Only the print form varies. One of these days a user is going to find a case where that matters....
Hi Stavros. Perhaps I wasn't explicit enough, or perhaps I'm misunderstanding what you're looking for, but I did provide an example above showing a simple and purely Maxima-level mathematical function that yields different results for
0.0and-0.0under a lisp implementation that supports negative zeros. This provides a way to distinguish between0.0and-0.0without relying on their print representation.The results from another implementation that does not support negative zeros (which is allowed by the standard) would be different (and so inconsistent across implementations).
I answered too quickly. Thanks for your diagnostic example.
So what do we think? Should Maxima should try to normalize -0.0 to 0.0 so that atan2(0.0,-1.0)=atan2(-0.0,1.0)?
What about bfloats? Bfloats don't have a negative zero, but atan2(0.0b0,-1.0b0) gives -3.14...
When I implemented a bunch of the special functions for bigfloats and maybe for regular floats (complex), I used the algorithms from cmucl with came from Kahan, which used signed zeroes a lot.
I think that Robert changed these so as not to do different things based on the sign of zero.