This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author akira
Recipients akira,, gladman, mark.dickinson, scoder, vstinner
Date 2014-09-24.11:43:38
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
Whether or not gcd(a, b) == gcd(|a|, |b|) depends on the definition if
we believe to Stepanov of C++ STL fame who mentions in his lecture [1]


that the current implementation that uses two operation __bool__ and 

  def gcd(a, b):
      while b:
          a, b = b, a%b
      return a

can be applied to Euclidean ring elements (not just positive or
negative integers). Despite Knuth’s objection to gcd(1, -1) = -1, 
adding `if a < 0: a = -a` at the end changes the requirements for the
type. Here's the definition from the lecture [1]:

  Greatest common divisor is a common divisor that is divisible by any 
  other common divisor.

I have no opinion on whether or not fractions.gcd() should be changed. 
I thought that I should mention that different definitions exist.
Date User Action Args
2014-09-24 11:43:39akirasetrecipients: + akira, mark.dickinson, scoder, vstinner, gladman,
2014-09-24 11:43:39akirasetmessageid: <>
2014-09-24 11:43:39akiralinkissue22477 messages
2014-09-24 11:43:38akiracreate