mirror of
git://git.sv.gnu.org/emacs.git
synced 2026-02-16 17:24:23 +00:00
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.
This commit is contained in:
parent
b76cdd0c1a
commit
60cd6cce55
2 changed files with 30 additions and 2 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue