[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 60cd6cc: Calc: GCD(0,x)=GCD(x,0)=|x|, not x (bug#41279)
From: |
Mattias Engdegård |
Subject: |
master 60cd6cc: Calc: GCD(0,x)=GCD(x,0)=|x|, not x (bug#41279) |
Date: |
Fri, 15 May 2020 14:15:53 -0400 (EDT) |
branch: master
commit 60cd6cce55744e8d3ae844e0602c9dd268dc4bc3
Author: Mattias Engdegård <address@hidden>
Commit: Mattias Engdegård <address@hidden>
Calc: GCD(0,x)=GCD(x,0)=|x|, not x (bug#41279)
Reported by David Ongaro.
* lisp/calc/calc-comb.el (calcFunc-gcd): Fix GCD simplification.
* test/lisp/calc/calc-tests.el (calc-gcd, calc-sum-gcd): New tests.
---
lisp/calc/calc-comb.el | 4 ++--
test/lisp/calc/calc-tests.el | 28 ++++++++++++++++++++++++++++
2 files changed, 30 insertions(+), 2 deletions(-)
diff --git a/lisp/calc/calc-comb.el b/lisp/calc/calc-comb.el
index d4562a0..c5d4d08 100644
--- a/lisp/calc/calc-comb.el
+++ b/lisp/calc/calc-comb.el
@@ -241,8 +241,8 @@
(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)
diff --git a/test/lisp/calc/calc-tests.el b/test/lisp/calc/calc-tests.el
index 9e36d91..c8cb97a 100644
--- a/test/lisp/calc/calc-tests.el
+++ b/test/lisp/calc/calc-tests.el
@@ -368,6 +368,34 @@ An existing calc stack is reused, otherwise a new one is
created."
(vec 0 0 (var a var-a) 0)))
'(neg (var a var-a)))))
+(ert-deftest calc-gcd ()
+ (should (equal (calcFunc-gcd 3 4) 1))
+ (should (equal (calcFunc-gcd 12 15) 3))
+ (should (equal (calcFunc-gcd -12 15) 3))
+ (should (equal (calcFunc-gcd 12 -15) 3))
+ (should (equal (calcFunc-gcd -12 -15) 3))
+ (should (equal (calcFunc-gcd 0 5) 5))
+ (should (equal (calcFunc-gcd 5 0) 5))
+ (should (equal (calcFunc-gcd 0 -5) 5))
+ (should (equal (calcFunc-gcd -5 0) 5))
+ (should (equal (calcFunc-gcd 0 0) 0))
+ (should (equal (calcFunc-gcd 0 '(var x var-x))
+ '(calcFunc-abs (var x var-x))))
+ (should (equal (calcFunc-gcd '(var x var-x) 0)
+ '(calcFunc-abs (var x var-x)))))
+
+(ert-deftest calc-sum-gcd ()
+ ;; sum(gcd(0,n),n,-1,-1)
+ (should (equal (math-simplify '(calcFunc-sum (calcFunc-gcd 0 (var n var-n))
+ (var n var-n) -1 -1))
+ 1))
+ ;; sum(sum(gcd(n,k),k,-1,1),n,-1,1)
+ (should (equal (math-simplify
+ '(calcFunc-sum
+ (calcFunc-sum (calcFunc-gcd (var n var-n) (var k var-k))
+ (var k var-k) -1 1)
+ (var n var-n) -1 1))
+ 8)))
(provide 'calc-tests)
;;; calc-tests.el ends here
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- master 60cd6cc: Calc: GCD(0,x)=GCD(x,0)=|x|, not x (bug#41279),
Mattias Engdegård <=