[Python-ideas] Python Float Update
drekin at gmail.com
drekin at gmail.com
Wed Jun 3 17:00:36 CEST 2015
> On Mon, Jun 01, 2015 at 06:27:57AM +0000, Nicholas Chammas wrote:
>
>> Having decimal literals or something similar by default, though perhaps
>> problematic from a backwards compatibility standpoint, is a) user friendly,
>> b) easily understandable, and c) not surprising to beginners. None of these
>> qualities apply to float literals.
>
> I wish this myth about Decimals would die, because it isn't true. The
> only advantage of base-10 floats over base-2 floats -- and I'll admit it
> can be a big advantage -- is that many of the numbers we commonly care
> about can be represented in Decimal exactly, but not as base-2 floats.
> In every other way, Decimals are no more user friendly, understandable,
> or unsurprising than floats. Decimals violate all the same rules of
> arithmetic that floats do. This should not come as a surprise, since
> decimals *are* floats, they merely use base 10 rather than base 2.
You are definitely right in "float vs. Decimal as representation of a real", but there is also a syntactical point that interpreting a float literal as Decimal rather than binary float is more natural since the literal itself *is* decimal.
The there would be no counterpart of the following situation if the float literal was interpreted as Decimal rather than binary float.
>>> 0.1
0.1
>>> Decimal(0.1)
Decimal('0.1000000000000000055511151231257827021181583404541015625')
Regards, Drekin
More information about the Python-ideas
mailing list