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


Groups > comp.lang.python > #87828

Re: Best way to calculate fraction part of x?

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 <skip.montanaro@gmail.com>
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 <skip.montanaro@gmail.com>
To "Steven D'Aprano" <steve+comp.lang.python@pearwood.info>
Cc Python <python-list@python.org>
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 <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.65.1427115770.10327.python-list@python.org> (permalink)
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

Show key headers only | View raw


On Mon, Mar 23, 2015 at 7:52 AM, Steven D'Aprano
<steve+comp.lang.python@pearwood.info> 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

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


Thread

Best way to calculate fraction part of x? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-03-23 23:52 +1100
  Re: Best way to calculate fraction part of x? Skip Montanaro <skip.montanaro@gmail.com> - 2015-03-23 08:02 -0500
  Re: Best way to calculate fraction part of x? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-03-23 13:11 +0000
  Re: Best way to calculate fraction part of x? wxjmfauth@gmail.com - 2015-03-23 06:17 -0700
  Re: Best way to calculate fraction part of x? Emile van Sebille <emile@fenx.com> - 2015-03-23 17:38 -0700
  Re: Best way to calculate fraction part of x? Jason Swails <jason.swails@gmail.com> - 2015-03-24 21:39 -0400
  Re: Best way to calculate fraction part of x? Emile van Sebille <emile@fenx.com> - 2015-03-26 13:48 -0700
  Re: Best way to calculate fraction part of x? Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2015-03-26 21:59 +0000
  Re: Best way to calculate fraction part of x? Russell Owen <rowen@uw.edu> - 2015-03-26 15:02 -0700

csiph-web