[New-bugs-announce] [issue22477] GCD in Fractions

Brian Gladman report at bugs.python.org
Wed Sep 24 09:25:02 CEST 2014


New submission from Brian Gladman:

There is a discussion of this issue on comp.lang.python

The function known as 'the greatest common divisor' has a number of well defined mathematical properties for both positive and negative integers (see, for example, Elementary Number Theory by Kenneth Rosen). In particular gcd(a, b) = gcd(|a|, |b|).  

But the Python version of this function in the fractions module doesn't conform to these properties since it returns a negative value when its second parameter is negative.  

This behaviour is documented but I think it is undesirable to provide a function that has the well known and widely understood name 'gcd', but one that doesn't match the behaviour normally associated with this function.

I hence believe that consideration should be given to changing the behaviour of the Python greatest common divisor function to match the mathematical properties expected of this function.  If necessary a local function in the fractions module could maintain the current behaviour.

----------
components: Library (Lib)
messages: 227410
nosy: brg at gladman.plus.com
priority: normal
severity: normal
status: open
title: GCD in Fractions
type: behavior
versions: Python 3.4

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue22477>
_______________________________________


More information about the New-bugs-announce mailing list