From: "Mattias Engdegård" <mattiase@acm.org>
To: David Ongaro <david.ongaro@hamburg.de>
Cc: 41279@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 [thread overview]
Message-ID: <7D48D15C-1F8E-41C8-9B1C-650215C8101D@acm.org> (raw)
In-Reply-To: <BB92B19F-35FA-41EB-90E7-A7E1A77F78DA@contoso.com>
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)
next prev parent reply other threads:[~2020-05-15 10:19 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-15 4:52 bug#41279: 26.3; Calc: sum(gcd(0,n),n,-1,-1) evaluates to -1 David Ongaro
2020-05-15 10:19 ` Mattias Engdegård [this message]
2020-05-15 17:44 ` David Ongaro
2020-05-15 18:21 ` Mattias Engdegård
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7D48D15C-1F8E-41C8-9B1C-650215C8101D@acm.org \
--to=mattiase@acm.org \
--cc=41279@debbugs.gnu.org \
--cc=david.ongaro@hamburg.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).