Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Yann Kaiser Newsgroups: comp.lang.python Subject: Re: How to simulate C style integer division? Date: Thu, 21 Jan 2016 08:42:02 +0000 Lines: 29 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: news.uni-berlin.de 8SFLj2XcDG1GZHFEFoO95QA+bhD4kLtevRQAgqD1dX5w== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'else:': 0.03; '21,': 0.07; 'subject:How': 0.09; 'operator,': 0.09; 'jan': 0.11; 'received:74.125.82.44': 0.15; 'thu,': 0.15; 'python3.': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'simulate': 0.16; 'wrote:': 0.16; 'integer': 0.18; '>': 0.18; 'math': 0.20; 'to:2**1': 0.21; 'import': 0.24; 'header:In-Reply-To:1': 0.24; "i've": 0.25; 'message-id:@mail.gmail.com': 0.27; 'division': 0.29; 'way?': 0.29; 'url:mailman': 0.30; 'url:python': 0.33; 'url:listinfo': 0.34; 'received:google.com': 0.35; 'received:74.125.82': 0.35; 'too': 0.36; 'should': 0.36; 'url:org': 0.36; 'to:addr:python-list': 0.36; 'subject:?': 0.36; 'subject:: ': 0.37; 'hi,': 0.38; 'url:mail': 0.40; 'to:addr:python.org': 0.40; 'url:me': 0.64; '8bit%:100': 0.70; 'skip:\xe5 40': 0.84; 'to:name:python': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :content-type; bh=jrW6W01lOEEUNJluhx+blokBkIX6a3tteZr4rGLKfhg=; b=ivrKDVZAgpfJWoOtGK8YgAS/nyYyvY6IhPJFcJacgaZpZzsKhWtQZNKJcec9f0kkcM fr1JAO+5EX+hK7mA6xZl385FZpkkxpwB56WhTkf5NBVNafbVCz3+ItFput1LinatFQwr YdKomU7MDmoGzqghCSKeqAmFtPy/NOys1e+NRuytESXhR3k3LBbiOmaikDBnv4IyJLo4 CcepulpMSLI3hH4OwNC/cTlt8+iSL77EmXHOnM7UNgVnaFJXj0669kxGlQfrbm1oyF2H TSAqpBLC7ACI406t0TPLI+c95R7BxkOL10aKSzcTPIOPMgrAvkSwC9Ch+Y3cSmg1+Tgg ocWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:content-type; bh=jrW6W01lOEEUNJluhx+blokBkIX6a3tteZr4rGLKfhg=; b=IiG+EH3Wty6P5oMfXVqamBCrJmEbqaYYBgEVl/Liy7UqGXptyMAS9Exh6HhtHd+e7k R1O+pqYS+52D4f0l4eO7WKLreyWx4bDwBCijPLKIw9/V/jguWZUWbN5VuazgH6uZoUiz LeyQL+SXwtlr6hRpa8ciuhWxgO1E05qRsq2V6yvxmHqf7RgKBS1MIZ4WSBHNsA6GN4XI xXRR511T4F6iS/HvYWFQ4fD3GkgXpL9VFfHpaRpHC/IqJh/Fd47n5GUKpKsos7RTsouv MvgDDAIchnhmejfOiqTePj87JM7XxQ8NS7Fml6vIewnjExBGKK6bdQZhPbAvzTO36yzt gEhg== X-Gm-Message-State: AG10YOT45j4EHaWXcwHap5XYtBiinbEgh1c1oXgbLQTO+VFJ+h/mn/4qsDaV5T8Vr7wTxJB6n29LDijjzVGG/Q== X-Received: by 10.194.6.165 with SMTP id c5mr28919005wja.88.1453365732267; Thu, 21 Jan 2016 00:42:12 -0800 (PST) In-Reply-To: X-Content-Filtered-By: Mailman/MimeDel 2.1.20+ X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:101948 You can use the // operator, which should do what you want. On Thu, Jan 21, 2016, 09:40 Shiyao Ma wrote: > Hi, > > I wanna simulate C style integer division in Python3. > > So far what I've got is: > # a, b =3D 3, 4 > > import math > result =3D float(a) / b > if result > 0: > result =3D math.floor(result) > else: > result =3D math.ceil(result) > > > I found it's too laborious. Any quick way? > > -- > > =E5=90=BE=E8=BC=A9=E3=81=AF=E7=8C=AB=E3=81=A7=E3=81=82=E3=82=8B=E3=80=82= =E3=83=9B=E3=83=BC=E3=83=A0=E3=83=BC=E3=83=9A=E3=83=BC=E3=82=B8=E3=81=AFhtt= ps://introo.me =E3=80=82 > -- > https://mail.python.org/mailman/listinfo/python-list >