Hacker News new | ask | show | jobs
by amyjess 3577 days ago
This really makes me wish they made the decision for Python 3 to auto-convert these literals to Fraction objects like Perl 6 does.

Basically, autoconvert the above to this (and make Fraction a builtin instead of in the standard library, of course):

    >>> Fraction('2.2') * Fraction('3.0') == Fraction('3.3') * Fraction('2.0')
    True
1 comments

The speed of these operations isn't on the same order of magnitude as floating-point operations. I do agree that literals for `Fraction` and `Decimal` would be interesting.

Also, I think that '2.2' is better represented as `Decimal`, as it's a decimal number (which is a subset of rational numbers, that are usually better represented using `Decimal`) (edit: that of course depends on the use case, as Decimal uses fixed-point precision).