GNU bug report logs - #17556
24.4.50; fix math-bignum

Previous Next

Package: emacs;

Reported by: Leo Liu <sdl.web <at> gmail.com>

Date: Fri, 23 May 2014 04:48:01 UTC

Severity: normal

Found in version 24.4.50

Done: Leo Liu <sdl.web <at> gmail.com>

Bug is archived. No further changes may be made.

Full log


Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Leo Liu <sdl.web <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 24.4.50; fix math-bignum
Date: Fri, 23 May 2014 12:46:05 +0800
Due to integer overflow (math-bignum most-negative-fixnum) is incorrect.
Any objection if I fix it like in this patch:

=== modified file 'lisp/calc/calc.el'
--- lisp/calc/calc.el	2014-01-01 07:43:34 +0000
+++ lisp/calc/calc.el	2014-05-23 04:42:18 +0000
@@ -2773,9 +2773,15 @@
 
 ;; Coerce integer A to be a bignum.  [B S]
 (defun math-bignum (a)
-  (if (>= a 0)
-      (cons 'bigpos (math-bignum-big a))
-    (cons 'bigneg (math-bignum-big (- a)))))
+  (cond
+   ((>= a 0)
+    (cons 'bigpos (math-bignum-big a)))
+   ((= a most-negative-fixnum)
+    ;; Note: (- most-negative-fixnum) is most-negative-fixnum
+    (math-sub (cons 'bigneg (math-bignum-big (- (1+ a))))
+	      1))
+   (t
+    (cons 'bigneg (math-bignum-big (- a))))))
 
 (defun math-bignum-big (a)   ; [L s]
   (if (= a 0)




This bug report was last modified 11 years and 6 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.