Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Shiyao Ma Newsgroups: comp.lang.python Subject: How to simulate C style integer division? Date: Thu, 21 Jan 2016 16:39:18 +0800 Lines: 22 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: news.uni-berlin.de im1cTNsPIg5SNOce0chC8wo3eO49eHHS2AUZhXS+8+OA== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.043 X-Spam-Evidence: '*H*': 0.92; '*S*': 0.00; 'else:': 0.03; 'subject:How': 0.09; 'python3.': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'simulate': 0.16; 'integer': 0.18; '>': 0.18; 'math': 0.20; 'import': 0.24; "i've": 0.25; 'message-id:@mail.gmail.com': 0.27; 'division': 0.29; 'way?': 0.29; 'received:google.com': 0.35; 'received:74.125.82': 0.35; 'too': 0.36; 'to:addr:python-list': 0.36; 'subject:?': 0.36; 'hi,': 0.38; 'to:addr:python.org': 0.40; 'url:me': 0.64; '8bit%:100': 0.70; 'received:74.125.82.47': 0.84; 'skip:\xe5 40': 0.84; 'to:name:python': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=introo-me.20150623.gappssmtp.com; s=20150623; h=mime-version:date:message-id:subject:from:to:content-type; bh=+ddTMUXt2E+Yec/UXo6kHVOoG4NAsdQrkgVpxGgK01I=; b=fgWX/T8zf1rYpGnWMl65xsB8y1jUmVCBfuD5KqVJVM8FeQeO6dyjGK9VQOAgNAR/1D 0nmT1/m5KSeTsrnLTqKG1t/nvSTp1R1HioNDO/I/xb98NxcOkWeBgoz+55dU01wSsfbk nl9dnbcCy7mGkqBiPpj+n0tizjavnMOuCq+Kkdt+2g4gkOjchPY3c6heVfbhZyK0GuO6 3A6Qlr1WzzZWCn6ktXC70c4end14ad7wmuJ4TDrIUb66TQ4Z+YKE4lBgiK5Fgi7KFybS ReI6DmYWTwlRlSxhLXnnMbPxH9LlNk0asg3oO9irqvF7YoNGaDKK5jOshsJDTSZRwvZi w+ug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:date:message-id:subject:from:to :content-type; bh=+ddTMUXt2E+Yec/UXo6kHVOoG4NAsdQrkgVpxGgK01I=; b=iTalwcCyISf/tIAyYDeOBWCjx4X/PLToXlRZiZA1XK5HvAK7fIUzzYhO6hbLV/Wq7j tCVuz5z8PMX/umiuaEwpJfs+s1vQd+VQVHer9x4xUnmqUw/C5uiIWpkVjzGQjfpsrnWy Rh32FeV/9/ZpNNlM5oiLuN5HnMsvuJybOG9bOUfH+l9ctqTmN/eJFWvTUbfe0mPcgKh+ UZaDWTSfEEopF6JYXTYQ+fenUPsIEZdcKTV/6ydON8CV0LwzVWNpo+onKa+gyOjroY5Y TwuDgjJxZeTiIGqNFoaBmmEksoyDnEWppgRhRvPszBmBwL1zEmRTqmFLSJauN3yBkT2N R4oQ== X-Gm-Message-State: ALoCoQkTqL+Jz/ZykygIJKOcQv5FnxWYwi1vXJovx+PCMRvkj6+z/6IMkGaEzx2kbklgUePoGp9GXN8krHMWslCQUHn1hXNjRw== X-Received: by 10.194.235.137 with SMTP id um9mr46528450wjc.146.1453365558827; Thu, 21 Jan 2016 00:39:18 -0800 (PST) X-Originating-IP: [143.89.244.107] 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:101946 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? --=20 =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=AFhttps:= //introo.me =E3=80=82