<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Fri, Mar 7, 2014 at 6:15 PM, Guido van Rossum <span dir="ltr"><<a href="mailto:guido@python.org" target="_blank">guido@python.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">
<div class="">Or, Decimal(repr(some_float)), which DWIM.<br></div></div></div></div></blockquote><div><br></div><div>Because I haven't seen anyone else bring this up, using a non-exact conversion breaks the invariant "Decimal(f)==f".</div>
<div><br></div><div>There are so many pairs of numeric types that break that invariant that it might not be a big deal; but in all other cases the invariant is broken because it is theoretically impossible.<br></div><div>
<br></div></div></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div class="gmail_extra"><div class="gmail_quote"><div>from decimal import Decimal</div></div></div><div class="gmail_extra"><div class="gmail_quote">
<div><div>f = 2.2</div></div></div></div><div class="gmail_extra"><div class="gmail_quote"><div><div>print(Decimal(f)==f)</div></div></div></div><div class="gmail_extra"><div class="gmail_quote"><div><div>print(Decimal(repr(f))==f)</div>
</div></div></div></blockquote><div class="gmail_extra"><div class="gmail_quote"><div><br></div><div>p</div></div></div></div>