On Tue, Jan 1, 2013 at 12:07 AM, Steven D'Aprano <st...@pearwood.info> wrote:
>
> Again, I was mistaken. x%1 is not suitable to get the fraction part of a
> number in Python: it returns the wrong result for negative values. You need
> math.modf:
>
> py> x = -99.25
> py> x % 1  # want -0.25
> 0.75
> py> math.modf(x)
> (-0.25, -99.0)

math.modf wraps libm's modf, which takes a double. This isn't suitable
for Decimal, Fraction, or a custom number type. What's wrong with
using math.trunc for this?
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to