Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.007 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'bug.': 0.09; 'negative.': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.11; 'jan': 0.12; '-1,': 0.16; 'rationale': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'wrote:': 0.18; 'example': 0.22; 'header:User- Agent:1': 0.23; 'header:X-Complaints-To:1': 0.27; 'header:In- Reply-To:1': 0.27; 'am,': 0.29; 'doc': 0.31; 'languages': 0.32; 'says': 0.33; '"the': 0.34; 'common': 0.35; 'test': 0.35; 'returning': 0.36; 'to:addr:python-list': 0.38; 'previous': 0.38; 'rather': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'greatest': 0.60; 'negative': 0.60; "'if": 0.84; 'received:fios.verizon.net': 0.84; 'received:108': 0.93 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: GCD in Fractions Date: Tue, 23 Sep 2014 15:31:39 -0400 References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: pool-108-16-203-145.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 24 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1411500739 news.xs4all.nl 2895 [2001:888:2000:d::a6]:40641 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:78243 On 9/23/2014 4:16 AM, blindanagram wrote: > What is the rationale for gcd(x, y) in Fractions returning a negative > value when y is negtive? > For example gcd(3, -7) returns -1, Since the doc says "the result will have the same sign as b", this is intentinal. However, I consider this a *design* bug. Both -1 and +1 are common divisors, and 1 is the greatest. So I consider the previous line "Calculate the Greatest Common Divisor of a and b" to be incorrect. > which means that a co-prime test that > would work in many other languages 'if gcd(x, y) == 1' will fail in > Python for negative y. > > And, of course, since -|x| is less than |x|, returning -|x| rather than > |x| is not returning the greatest common divisor of x and y when y is > negative. > -- Terry Jan Reedy