[Python-Dev] Mixing float and Decimal -- thread reboot (original) (raw)
Guido van Rossum guido at python.org
Fri Apr 2 19:10:43 CEST 2010
- Previous message: [Python-Dev] Mixing float and Decimal -- thread reboot
- Next message: [Python-Dev] 5 : 1
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Fri, Apr 2, 2010 at 2:38 AM, Mark Dickinson <dickinsm at gmail.com> wrote:
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.fromfloat() because decimals weren't interoperable with floats. Not sure this follows; Fraction(1.1) raises an exception, you have to use Fraction.fromfloat(). 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.fromfloat(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.
Agreed. If people don't learn about from_float() they might do weird stuff like Decimal(0) + 1.1. Making Fraction and Decimal do the same thing should be easy enough.
-- --Guido van Rossum (python.org/~guido)
- Previous message: [Python-Dev] Mixing float and Decimal -- thread reboot
- Next message: [Python-Dev] 5 : 1
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]