[Python-Dev] Mixing float and Decimal -- thread reboot

Mark Dickinson dickinsm at gmail.com
Fri Apr 2 11:38:02 CEST 2010


On Mon, Mar 22, 2010 at 7:52 PM, Guido van Rossum <guido at python.org> wrote:
> On Mon, Mar 22, 2010 at 11:36 AM, Raymond Hettinger
> <raymond.hettinger at gmail.com> wrote:
>> One other thought.
>>
>> The Decimal constructor should now accept floats as a possible input type.
>> Formerly, we separated that out to Decimal.from_float() because
>> decimals weren't interoperable with floats.
>
> Not sure this follows; Fraction(1.1) raises an exception, you have to
> use Fraction.from_float().

Is there any good reason for this, other than a parallel with Decimal?
 It seems to me that Raymond's arguments for allowing direct
construction of a Decimal from a float apply equally well to the
Fraction type.

If we're going to allow Decimal(1.1), I'd like to allow Fraction(1.1)
to succeed as well (giving the equivalent of
Fraction.from_float(1.1)).

The main argument against allowing this (for both Fraction and
Decimal) seems to be that the result of Decimal(1.1) or Fraction(1.1)
could be confusing.  But it's an immediate, explicit confusion, which
can be quickly resolved by pointing the confusee to the section on
floating-point in the appendix, so I don't find this objection
particularly compelling.

Mark


More information about the Python-Dev mailing list