Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #101985

Re: How to simulate C style integer division?

Path csiph.com!feeder.erje.net!2.eu.feeder.erje.net!newsfeed0.kamp.net!newsfeed.kamp.net!fu-berlin.de!uni-berlin.de!not-for-mail
From Random832 <random832@fastmail.com>
Newsgroups comp.lang.python
Subject Re: How to simulate C style integer division?
Date Thu, 21 Jan 2016 14:52:08 -0500
Lines 8
Message-ID <mailman.155.1453405932.15297.python-list@python.org> (permalink)
References <CAJQX3DyoDUtNWbNEpGVJxeKATADWAikP47NRZb7+UaxSwSRZaQ@mail.gmail.com> <mailman.143.1453367498.15297.python-list@python.org> <56a0d24f$0$1614$c3e8da3$5496439d@news.astraweb.com> <lf5mvrzuj5z.fsf@ling.helsinki.fi> <87mvrzc8bx.fsf@elektro.pacujo.net>
Mime-Version 1.0
Content-Type text/plain
Content-Transfer-Encoding 7bit
X-Trace news.uni-berlin.de uaavshCEEaeJL6SpVESoEAzEAO3NXwmgoN8kAlXtpA9Q==
Return-Path <random832@fastmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; '21,': 0.07; 'subject:How': 0.09; 'received:internal': 0.09; 'jan': 0.11; 'def': 0.13; 'thu,': 0.15; 'b):': 0.16; 'division.': 0.16; 'message- id:@webmail.messagingengine.com': 0.16; 'opposite': 0.16; 'personally,': 0.16; 'received:10.202': 0.16; 'received:10.202.2': 0.16; 'received:10.202.2.44': 0.16; 'received:66.111': 0.16; 'received:66.111.4': 0.16; 'received:66.111.4.27': 0.16; 'received:compute4.internal': 0.16; 'received:io': 0.16; 'received:messagingengine.com': 0.16; 'received:out3-smtp.messagingengine.com': 0.16; 'received:psf.io': 0.16; 'wrote:': 0.16; 'header:In-Reply-To:1': 0.24; "i've": 0.25; 'done': 0.35; 'to:addr:python-list': 0.36; 'subject:?': 0.36; 'subject:: ': 0.37; 'received:10': 0.37; 'received:66': 0.38; 'to:addr:python.org': 0.40; 'header:Message-Id:1': 0.61
DKIM-Signature v=1; a=rsa-sha1; c=relaxed/relaxed; d=fastmail.com; h= content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-sasl-enc :x-sasl-enc; s=mesmtp; bh=Cu9x5zEz5sRJCo1RkPpLaaGvyEU=; b=Yo8iIP 3P0NTK/nvPiW/cOib+Jq9SuweGLZ9NG0a2/VHYnB4SpG1EzxD/EtHq4QDf7W20Ri tpiynpMpVkebdA9UXrihANtdt/dgU/heNyLZT+LRd1h3UT953LdcJfBoy3fex7sX VhPmdVSbwmsMHosXOG32elIeuV6mzuBKFhUOk=
DKIM-Signature v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-sasl-enc:x-sasl-enc; s=smtpout; bh=Cu9x5zEz5sRJCo1 RkPpLaaGvyEU=; b=ubKqNwM+bUMopdX6zvI/jSNgLT7WXXBn6mlKbJqhbUjuivL L+WOYUtNc14fV+WUwOFaqHu1Daoo6VYSF1NahFBpAZcE7E1IP3GSL6tvh6iVYhzH eLHr/ZBDRm1JNOFtO8mMjrtGUeS06YA5NNgCa78fzLN/mmXgCpxF7ierUhlI=
X-Sasl-Enc 5+JYxKoHiLq/0raRVd7liQ8bVVUTfs8NQ08BbzBOokzg 1453405928
X-Mailer MessagingEngine.com Webmail Interface - ajax-6cda141f
In-Reply-To <87mvrzc8bx.fsf@elektro.pacujo.net>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
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>
Xref csiph.com comp.lang.python:101985

Show key headers only | View raw


On Thu, Jan 21, 2016, at 09:31, Marko Rauhamaa wrote:
> Maybe:
> 
>    def intdiv(a, b):
>        return a // b if (a < 0) == (b < 0) else -(-a // b)

Personally, I like a // b + (a % b and a ^ b < 0) - I've done the
opposite in C to get python-style division.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: How to simulate C style integer division? Ben Finney <ben+python@benfinney.id.au> - 2016-01-21 20:11 +1100
  Re: How to simulate C style integer division? Paul Rubin <no.email@nospam.invalid> - 2016-01-21 01:43 -0800
    Re: How to simulate C style integer division? Jussi Piitulainen <jussi.piitulainen@helsinki.fi> - 2016-01-21 11:58 +0200
  Re: How to simulate C style integer division? Steven D'Aprano <steve@pearwood.info> - 2016-01-21 23:42 +1100
    Re: How to simulate C style integer division? Jussi Piitulainen <jussi.piitulainen@helsinki.fi> - 2016-01-21 16:00 +0200
      Re: How to simulate C style integer division? Marko Rauhamaa <marko@pacujo.net> - 2016-01-21 16:31 +0200
        Re: How to simulate C style integer division? Jussi Piitulainen <jussi.piitulainen@helsinki.fi> - 2016-01-21 16:48 +0200
        Re: How to simulate C style integer division? Random832 <random832@fastmail.com> - 2016-01-21 14:52 -0500
          Re: How to simulate C style integer division? Marko Rauhamaa <marko@pacujo.net> - 2016-01-21 23:17 +0200
            Re: How to simulate C style integer division? Matt Wheeler <m@funkyhat.org> - 2016-01-22 00:51 +0000
      Re: How to simulate C style integer division? Wolfgang Maier <wolfgang.maier@biologie.uni-freiburg.de> - 2016-01-21 15:22 +0100

csiph-web