[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 204273c 1/2: Fix byte-compilation of (+ -0.0) (bug#42597)
From: |
Mattias Engdegård |
Subject: |
master 204273c 1/2: Fix byte-compilation of (+ -0.0) (bug#42597) |
Date: |
Fri, 7 Aug 2020 04:48:47 -0400 (EDT) |
branch: master
commit 204273c3b9f0a77459661790aa929f86067a9ab1
Author: Mattias Engdegård <mattiase@acm.org>
Commit: Mattias Engdegård <mattiase@acm.org>
Fix byte-compilation of (+ -0.0) (bug#42597)
* lisp/emacs-lisp/bytecomp.el (byte-compile-associative):
Translate numerical identity expressions, such as (+ x) and (* x),
into (* x 1) since the previous translation (+ x 0) gets it wrong
for x = -0.0.
* test/lisp/emacs-lisp/bytecomp-tests.el
(byte-opt-testsuite-arith-data): Add test cases.
---
lisp/emacs-lisp/bytecomp.el | 6 +++---
test/lisp/emacs-lisp/bytecomp-tests.el | 5 +++++
2 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el
index 22e648e..8f76a3a 100644
--- a/lisp/emacs-lisp/bytecomp.el
+++ b/lisp/emacs-lisp/bytecomp.el
@@ -3733,7 +3733,7 @@ discarding."
;; Compile a function that accepts one or more args and is right-associative.
;; We do it by left-associativity so that the operations
;; are done in the same order as in interpreted code.
-;; We treat the one-arg case, as in (+ x), like (+ x 0).
+;; We treat the one-arg case, as in (+ x), like (* x 1).
;; in order to convert markers to numbers, and trigger expected errors.
(defun byte-compile-associative (form)
(if (cdr form)
@@ -3748,8 +3748,8 @@ discarding."
(setq args (copy-sequence (cdr form)))
(byte-compile-form (car args))
(setq args (cdr args))
- (or args (setq args '(0)
- opcode (get '+ 'byte-opcode)))
+ (or args (setq args '(1)
+ opcode (get '* 'byte-opcode)))
(dolist (arg args)
(byte-compile-form arg)
(byte-compile-out opcode 0))))
diff --git a/test/lisp/emacs-lisp/bytecomp-tests.el
b/test/lisp/emacs-lisp/bytecomp-tests.el
index c235dd4..8949143 100644
--- a/test/lisp/emacs-lisp/bytecomp-tests.el
+++ b/test/lisp/emacs-lisp/bytecomp-tests.el
@@ -47,6 +47,11 @@
(let ((a 1.0)) (/ 3 a 2))
(let ((a most-positive-fixnum) (b 2.0)) (* a 2 b))
(let ((a 3) (b 2)) (/ a b 1.0))
+ (let ((a -0.0)) (+ a))
+ (let ((a -0.0)) (- a))
+ (let ((a -0.0)) (* a))
+ (let ((a -0.0)) (min a))
+ (let ((a -0.0)) (max a))
(/ 3 -1)
(+ 4 3 2 1)
(+ 4 3 2.0 1)