[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#41279: 26.3; Calc: sum(gcd(0,n),n,-1,-1) evaluates to -1
From: |
Mattias Engdegård |
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)
- bug#41279: 26.3; Calc: sum(gcd(0,n),n,-1,-1) evaluates to -1, David Ongaro, 2020/05/15
- bug#41279: 26.3; Calc: sum(gcd(0,n),n,-1,-1) evaluates to -1,
Mattias Engdegård <=