A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2010-April/099052.html below:

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

[Python-Dev] Mixing float and Decimal -- thread rebootGuido van Rossum guido at python.org
Fri Apr 2 19:10:43 CEST 2010
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.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.

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)
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4