On Sat, Mar 8, 2014 at 10:49 AM, Mark Dickinson <dickinsm@gmail.com> wrote:
Accepted, but I believe the proposal would break a number of other expectations too with respect to ints and floats.  For one, we currently have the unsurprising, and I believe desirable, property that conversion to Decimal is monotonic: for any finite numbers (int, float or Decimal) x and y,  if x <= y then Decimal(x) <= Decimal(y).  The proposal would break that property, too: you could find examples of an integer x and float y such that `x < y` and `Decimal(x) > Decimal(y)` would be simultaneously True.

I think that Mark Dickinson's point about breaking monotonicity is a STRONG argument against the proposal to change the meaning of Decimal(float_num) to produce Decimal(repr(float_num)).  That latter spelling is already available if anyone wants it.

The focus on float value that have been entered as literals feels like a distraction to me.  Floats come from other places as well, and making Decimal(float_num) produce the *exact* value feels far more desirable than producing "something which rounds to the same float.

As I think Guido has acknowledged in a recent post, a far better and more intuitive approach is just to make decimal literals easier to write.  Teaching users to write '3.14d' doesn't feel that hard to me, and it looks notably prettier than 'decimal.Decimal("3.14")'.  A *would* also like an optional explicit binary-float literal though, e.g. '3.14f'.  This wouldn't actually mean anything different from '3.14', but then "PI" doesn't mean anything different from u"PI" either.  The optional bin-float specifier, in principle, allows for some Python 4000 in which decimal is the default literal (although I don't think I'd ever support that, but no harm in letting that decision be made years from now).

- if we're aiming to eliminate surprises, the 'fix' doesn't go far enough: Decimal(1.1 + 2.2) will still surprise, as will Decimal(0.12345123451234512345)

This is a simple illustration of why the "do what I mean" goal of the proposed change will fall apart rather quickly for anything but the simplest examples.  The status quo of Decimal(float_num) producing the *exact* value continues to feel the best to me.

I've said too much already;  beyond registering my strong -1 on this proposal, I'm going to keep out of further discussion.

So yeah, me too: -1 on proposal.
 


--
Keeping medicines from the bloodstreams of the sick; food
from the bellies of the hungry; books from the hands of the
uneducated; technology from the underdeveloped; and putting
advocates of freedom in prisons.  Intellectual property is
to the 21st century what the slave trade was to the 16th.