On Mon, Mar 22, 2010 at 12:33 PM, Raymond Hettinger
<raymond.hettin...@gmail.com> wrote:
> While we're on the topic, I think you should consider allowing the Fraction()
> constructor to accept a decimal input.
>
> This corresponds to common schoolbook problems and simple client requests:
>   "Express 3.5 as a fraction".
>
>    >>> Fraction(Decimal('3.5'))
>   Fraction(7, 2)
>
> Unlike typical binary floats which use full precision, it is not uncommon
> to have decimal floats with only a few digits of precision where the
> expression as a fraction is both useful and unsurprising.

There is already a Fraction.from_decimal() class method. I understand
the reasons for not allowing floats in the unadorned Fraction
constructor don't quite hold for Decimal, but at the same time I'm not
sure how compelling the use case is for such downcasts given that it
can be done easily with an explicit call. (Same actually for requiring
Decimal.from_float().)

-- 
--Guido van Rossum (python.org/~guido)
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to