Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #78299
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <random832@fastmail.us> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.001 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'operator': 0.03; 'modulo': 0.09; 'received:internal': 0.09; 'used.': 0.09; 'python': 0.11; 'def': 0.12; '-2.': 0.16; '24,': 0.16; 'b):': 0.16; 'division,': 0.16; 'mathematics.': 0.16; 'message- id:@webmail.messagingengine.com': 0.16; 'negative,': 0.16; 'operation,': 0.16; 'received:10.202': 0.16; 'received:10.202.2': 0.16; 'received:66.111': 0.16; 'received:66.111.4': 0.16; 'received:messagingengine.com': 0.16; 'remainder': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'appears': 0.22; 'header:In-Reply-To:1': 0.27; 'returned': 0.30; 'sep': 0.31; 'allows': 0.31; 'entirely': 0.33; 'received:66': 0.35; 'computing': 0.35; 'should': 0.36; 'example,': 0.37; 'received:10': 0.37; 'depends': 0.38; 'to:addr :python-list': 0.38; 'issue': 0.38; 'to:addr:python.org': 0.39; 'either': 0.39; 'ian': 0.60; 'negative': 0.60; 'from:no real name:2**0': 0.61; 'header:Message-Id:1': 0.63; 'different': 0.65; 'when:': 0.68; '2014,': 0.84; 'whereas': 0.91 |
| DKIM-Signature | v=1; a=rsa-sha1; c=relaxed/relaxed; d=fastmail.us; h= message-id:from:to:mime-version:content-transfer-encoding :content-type:in-reply-to:references:subject:date; s=mesmtp; bh= AJJr0S+4uMyDKQoGGRv4fgPIXgg=; b=fc3P/gA/4u9FnYN54z5+7/REtcfSbaYm j7dkPECn1hL8mOhREQzf2PS5jw2A1ySyfu60Bl7enbGhL9D3F7xi4Y1HyHNYf3lT but74glqI8onJJvtXAmv+lWGSGl4VO0pwSK4vqz0+qcA8d+uwtPIjHD9o/x8ukIv zXkXRWV8dq8= |
| DKIM-Signature | v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=message-id:from:to:mime-version :content-transfer-encoding:content-type:in-reply-to:references :subject:date; s=smtpout; bh=AJJr0S+4uMyDKQoGGRv4fgPIXgg=; b=gwz ywdbTD8cuioqQop7yFMgqkjIPMBvHSKNNxtI/aIo28hTDclZyPX1mvLtnx2Hm4L/ YEOgtBzgAShjYEtmZmbsvbwLuOYCTiUxTWpfAS8ux+xs3Fs85YxSunb4xtyDLsOs UlM75oKq6238rBvRv5kRC9MbMSvioTYCaejb3t5M= |
| X-Sasl-Enc | siW0dOqL8D3BL8Y9JWqsl+EiBzZ4lo+lEr8j5crGuz2H 1411577376 |
| From | random832@fastmail.us |
| To | python-list@python.org |
| MIME-Version | 1.0 |
| Content-Transfer-Encoding | 7bit |
| Content-Type | text/plain |
| X-Mailer | MessagingEngine.com Webmail Interface - ajax-cad53418 |
| In-Reply-To | <CALwzidmb-oSPY4R=Cc3jz=aV1xqdUcjJ4h2usRcgXPgHrRQ5eQ@mail.gmail.com> |
| References | <pfGdnaNKbb7-sbzJnZ2dnUVZ8vudnZ2d@brightview.co.uk> <54216c8e$0$29966$c3e8da3$5496439d@news.astraweb.com> <lvs7lq$vrn$1@ger.gmane.org> <mailman.14277.1411493200.18130.python-list@python.org> <CYmdneCJKbm7LLzJnZ2dnUVZ7vadnZ2d@brightview.co.uk> <mailman.14280.1411494972.18130.python-list@python.org> <tfidne0ioO6jdbzJnZ2dnUVZ7rednZ2d@brightview.co.uk> <5422ae8b$0$29980$c3e8da3$5496439d@news.astraweb.com> <CALwzidmb-oSPY4R=Cc3jz=aV1xqdUcjJ4h2usRcgXPgHrRQ5eQ@mail.gmail.com> |
| Subject | Re: GCD in Fractions |
| Date | Wed, 24 Sep 2014 12:49:36 -0400 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.14324.1411577379.18130.python-list@python.org> (permalink) |
| Lines | 27 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1411577379 news.xs4all.nl 2873 [2001:888:2000:d::a6]:47158 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:78299 |
Show key headers only | View raw
On Wed, Sep 24, 2014, at 10:26, Ian Kelly wrote:
> This depends entirely on your implementation of the modulo operation,
> which is an issue of computing since the operator is not used in
> mathematics.
Wikipedia suggests that "remainders from Euclidean division" should be
used. In Euclidean division, the remainder is always positive. (whereas
either C or Python allows the modulo to be negative, in different
situations: in python [round quotient down] the modulo has the same sign
as b, whereas in C [round quotient to zero] the modulo has the same sign
as a).
def mod(a, b):
r = a % b
return r + abs(b) if r < 0 else r
def gcd(a, b):
if b == 0: return a
else: return gcd(b, mod(a, b))
This appears to give a negative result when:
a < 0 and b == 0, obviously. A is returned as the gcd.
a == 0 and b < 0. B is returned as the gcd
|a| is exactly divisible by |b| and b < 0. B is returned as the gcd.
However, it still lacks the symmetry of gcd(a, b) == gcd(b, a) in some
cases. For example, gcd(-2, 6) is 2, whereas gcd(6, -2) is -2.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
GCD in Fractions blindanagram <noone@nowhere.net> - 2014-09-23 09:16 +0100
Re: GCD in Fractions Wolfgang Maier <wolfgang.maier@biologie.uni-freiburg.de> - 2014-09-23 13:53 +0200
Re: GCD in Fractions blindanagram <noone@nowhere.net> - 2014-09-23 13:48 +0100
Re: GCD in Fractions Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-09-23 22:50 +1000
Re: GCD in Fractions blindanagram <noone@nowhere.net> - 2014-09-23 15:37 +0100
Re: GCD in Fractions Chris Angelico <rosuav@gmail.com> - 2014-09-24 00:42 +1000
Re: GCD in Fractions Wolfgang Maier <wolfgang.maier@biologie.uni-freiburg.de> - 2014-09-23 18:38 +0200
Re: GCD in Fractions Ian Kelly <ian.g.kelly@gmail.com> - 2014-09-23 11:20 -0600
Re: GCD in Fractions blindanagram <noone@nowhere.net> - 2014-09-23 18:31 +0100
Re: GCD in Fractions Stefan Behnel <stefan_ml@behnel.de> - 2014-09-23 19:26 +0200
Re: GCD in Fractions blindanagram <noone@nowhere.net> - 2014-09-23 18:43 +0100
Re: GCD in Fractions Stefan Behnel <stefan_ml@behnel.de> - 2014-09-23 19:55 +0200
Re: GCD in Fractions blindanagram <noone@nowhere.net> - 2014-09-23 22:38 +0100
Re: GCD in Fractions Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-09-24 21:44 +1000
Re: GCD in Fractions blindanagram <noone@nowhere.net> - 2014-09-24 14:25 +0100
Re: GCD in Fractions Stefan Behnel <stefan_ml@behnel.de> - 2014-09-24 18:13 +0200
Re: GCD in Fractions blindanagram <noone@nowhere.net> - 2014-09-24 18:05 +0100
Re: GCD in Fractions "Robert E. Beaudoin" <rbeaudoin@comcast.net> - 2014-09-24 19:19 -0400
Re: GCD in Fractions Ian Kelly <ian.g.kelly@gmail.com> - 2014-09-24 08:26 -0600
Re: GCD in Fractions random832@fastmail.us - 2014-09-24 12:49 -0400
Re: GCD in Fractions Terry Reedy <tjreedy@udel.edu> - 2014-09-24 13:42 -0400
Re: GCD in Fractions Johann Hibschman <jhibschman@gmail.com> - 2014-09-24 14:09 -0400
Re: GCD in Fractions Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-09-23 20:30 +0100
Re: GCD in Fractions blindanagram <noone@nowhere.net> - 2014-09-23 22:48 +0100
Re: GCD in Fractions Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-09-23 23:52 +0100
Re: GCD in Fractions Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-09-24 11:42 +0100
Re: GCD in Fractions Mark Dickinson <mdickinson@enthought.com> - 2014-09-24 11:14 +0000
Re: GCD in Fractions Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-09-24 17:34 +0100
Re: GCD in Fractions blindanagram <noone@nowhere.net> - 2014-09-24 18:31 +0100
Re: GCD in Fractions Akira Li <4kir4.1i@gmail.com> - 2014-09-25 14:56 +0400
Re: GCD in Fractions Chris Angelico <rosuav@gmail.com> - 2014-09-25 21:03 +1000
Re: GCD in Fractions Ian Kelly <ian.g.kelly@gmail.com> - 2014-09-23 11:39 -0600
Re: GCD in Fractions Ian Kelly <ian.g.kelly@gmail.com> - 2014-09-23 11:40 -0600
Re: GCD in Fractions Stefan Behnel <stefan_ml@behnel.de> - 2014-09-23 20:09 +0200
Re: GCD in Fractions Terry Reedy <tjreedy@udel.edu> - 2014-09-23 15:31 -0400
csiph-web