Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!bcyclone02.am1.xlned.com!bcyclone02.am1.xlned.com!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.027 X-Spam-Evidence: '*H*': 0.95; '*S*': 0.00; 'suppose': 0.07; 'cc:addr :python-list': 0.11; '23,': 0.16; 'int(x)': 0.16; 'to:addr:pearwood.info': 0.16; 'to:addr:steve+comp.lang.python': 0.16; "to:name:steven d'aprano": 0.16; 'wrote:': 0.18; 'cc:addr:python.org': 0.22; 'fraction': 0.24; 'skip': 0.24; 'mon,': 0.24; 'cc:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; "d'aprano": 0.31; 'faster,': 0.31; 'steven': 0.31; 'but': 0.35; 'received:google.com': 0.35; 'subject:?': 0.36; 'negative': 0.60; 'mar': 0.68; '2015': 0.84; 'subject:Best': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=eN6vQtrkjvruP+x6OCnxUKIBi49tNZPi6SDTAteUfgU=; b=zIvAhEEL40pghH0uY+0vtZ2GwfNeYqry/OvOX4I3XQvNWtlCMy7PEExjcTcp4GUX40 lwW9tHmZQlcsKSUFXQrQrt5RMipMgkbAhpuxUz2LtSH3Ny6Ko7Qg7NGFhlpteZKI0NbL UQhGMJq7pdRakCDdrAyuGFInLkRlXGEU0NzoD1KZwyoB6SfQiXS9hWSPHKrVDT3c349P PFq44+xvo75/JlFjAk8hWWRwc+R59WZN/0pVcBX1DmrhVpk/beR3cI0XnLS8lzM8zOuv F7Pre4GMtvemmyGLh/xxxpP3wb/8vUd4Y6pwq98lkOoDRuBAt2HzLnKLBlzoQlCCJTgg FS4Q== MIME-Version: 1.0 X-Received: by 10.202.90.3 with SMTP id o3mr70011467oib.99.1427115760970; Mon, 23 Mar 2015 06:02:40 -0700 (PDT) In-Reply-To: <55100c7a$0$13004$c3e8da3$5496439d@news.astraweb.com> References: <55100c7a$0$13004$c3e8da3$5496439d@news.astraweb.com> Date: Mon, 23 Mar 2015 08:02:40 -0500 Subject: Re: Best way to calculate fraction part of x? From: Skip Montanaro To: "Steven D'Aprano" Cc: Python Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.19 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 16 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1427115770 news.xs4all.nl 2931 [2001:888:2000:d::a6]:38494 X-Complaints-To: abuse@xs4all.nl X-Received-Bytes: 3279 X-Received-Body-CRC: 2371296598 Xref: csiph.com comp.lang.python:87828 On Mon, Mar 23, 2015 at 7:52 AM, Steven D'Aprano wrote: > x % 1 is significantly faster, but has the disadvantage of giving the > complement of the fraction if x is negative I suppose abs(x) % 1 would be just as slow as x - int(x) ? (haven't checked) Skip