bug#42597: 27.1; (+ -0.0) returns +0.0 when compiled

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

bug#42597: 27.1; (+ -0.0) returns +0.0 when compiled

Mattias Engdegård-2
Unary +, *, min and max, all of which should be identity for numbers, convert -0.0 to +0.0 when byte-compiled:

(defun f (x) (+ x))
(f -0.0)
=> -0.0
(byte-compile 'f)
(f -0.0)
=> 0.0

The reason is that byte-compile-associative transforms (+ x), (* x), (min x) and (max x) into (+ x 0).

No patch yet (sorry!) but I'm not sure what would be the best way to go about it. Some possibilities:

A. Use a full 1-argument call, like (+ x). This is more expensive (about 1.8×) since the general function call mechanism has to be used.
B. Use (* x 1) instead; this appears to work. This is also more expensive (1.6×); not sure why.
C. Add a new byte-op. Fast but probably overkill.

Better suggestions welcome!




Reply | Threaded
Open this post in threaded view
|

bug#42597: 27.1; (+ -0.0) returns +0.0 when compiled (fwd)

Alan Mackenzie

Hello, Mattias.

In article <[hidden email]> you wrote:
> Unary +, *, min and max, all of which should be identity for numbers,
> convert -0.0 to +0.0 when byte-compiled:

They convert what?

> (defun f (x) (+ x))
> (f -0.0)
> => -0.0
> (byte-compile 'f)
> (f -0.0)
> => 0.0

> The reason is that byte-compile-associative transforms (+ x), (* x),
> (min x) and (max x) into (+ x 0).

> No patch yet (sorry!) but I'm not sure what would be the best way to go
> about it. Some possibilities:

> A. Use a full 1-argument call, like (+ x). This is more expensive
>    (about 1.8×) since the general function call mechanism has to be used.
> B. Use (* x 1) instead; this appears to work. This is also more
>    expensive (1.6×); not sure why.
> C. Add a new byte-op. Fast but probably overkill.

> Better suggestions welcome!

This is an example of what happens when ignorant people rule the roost.
-0.0 and +0.0 are identically the same thing.  It should not take a
degree in mathematics (which I have) to realise this.  When you put
mathematical nonsense into <whatever thing is producing -0.0> you cannot
help but get nonsense back out.

0.0 does not need two different names.  It can do nothing but produce
confusion, what has clearly happened here at whatever level.

So my suggestion D. would be: Eliminate "-0.0" from Emacs Lisp.  If this
is not possible for whatever reason, then E. Do nothing.

--
Alan Mackenzie (Nuremberg, Germany).