Best way to calculate fraction part of x?

Skip Montanaro skip.montanaro at gmail.com
Mon Mar 23 09:02:40 EDT 2015


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



More information about the Python-list mailing list