GNU bug report logs - #41279
26.3; Calc: sum(gcd(0,n),n,-1,-1) evaluates to -1

Previous Next

Package: emacs;

Reported by: David Ongaro <david.ongaro <at> hamburg.de>

Date: Fri, 15 May 2020 04:54:02 UTC

Severity: normal

Found in version 26.3

Done: Mattias EngdegÄrd <mattiase <at> acm.org>

Bug is archived. No further changes may be made.

Full log


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

From: Mattias EngdegÄrd <mattiase <at> acm.org>
To: David Ongaro <david.ongaro <at> hamburg.de>
Cc: 41279 <at> debbugs.gnu.org
Subject: bug#41279: 26.3; Calc: sum(gcd(0,n),n,-1,-1) evaluates to -1 
Date: Fri, 15 May 2020 12:19:14 +0200
Thank you for reporting this. It seems that Calc first simplifies gcd(0,n) to n and then computes sum(n,n,-1,-1) = -1.
We could either make gcd(0,x)=gcd(x,0)=|x|, or try preventing sum from simplifying its operand first, or both.
For the smallest possible change, what about the hack below?

--- a/lisp/calc/calc-comb.el
+++ b/lisp/calc/calc-comb.el
@@ -241,8 +241,8 @@ calcFunc-gcd
         (calcFunc-gcd (math-neg a) b))
        ((Math-looks-negp b)
         (calcFunc-gcd a (math-neg b)))
-       ((Math-zerop a) b)
-       ((Math-zerop b) a)
+       ((Math-zerop a) (math-abs b))
+       ((Math-zerop b) (math-abs a))
        ((and (Math-ratp a)
              (Math-ratp b))
         (math-make-frac (math-gcd (if (eq (car-safe a) 'frac) (nth 1 a) a)






This bug report was last modified 5 years and 10 days ago.

Previous Next


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