Subject: Re: bug#41279: 26.3; Calc: sum(gcd(0,n),n,-1,-1) evaluates to -1

From: David Ongaro <[email-masked]>
Date: Fri, 15 May 2020 10:44:07 -0700

On 15.05.20, 03:19, "Mattias Engdegård" <[email-masked]> wrote:

> 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?

I see, so the simplest reproduction of the bug doesn't involve the sum, but just the evaluation of gcd(0, x) or gcd(x, 0). Your fix seems sensible to me, I don't see why you consider it a 'hack'. The simplification gcd(0, x)=gcd(x, 0)=abs(x) seems legit and matches the gcd definition "The largest positive integer that divides each of the integers".