<div><span class="q" style="color: rgb(85, 0, 85); "><span class="gmail_quote">On 9/30/07,&nbsp;<b class="gmail_sendername">Facundo Batista</b>&nbsp;&lt;<a href="mailto:facundobatista@gmail.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
facundobatista@gmail.com</a>&gt; wrote:</span><blockquote class="gmail_quote" style="margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex">2007/9/28, Rob Crowther &lt;<a href="mailto:weilawei@gmail.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
weilawei@gmail.com</a>&gt;:<br><br>&gt; a) MPF() now takes a float or integer argument because mpf_set_str is just<br><br>Rob, there has been a *lot* of discussion about this for Decimal (see&nbsp;<br>the PEP and discussions in python-dev and python-list around the PEP
<br>date).</blockquote><div><br>&nbsp;</div></span><div>But there&#39;s a major difference here: Decimal is *decimal* floating point, MPF and Python floats are *binary* floating point. &nbsp;</div><div><br>&nbsp;</div><div>So in the case of Decimal, conversion from a decimal string is a straightforward operation, while conversion from binary involves making choices about how to round, how many decimal digits to use, etc. &nbsp;
</div><div><br>&nbsp;</div><div>But for MPF it&#39;s the other way around: &nbsp;conversion from a float is immediate (the GMP precision is always at least 53 bits, so any IEEE double can be represented as an MPF with no loss of information), while conversion from a string involves hard work and decisions about how to round (and GMP&#39;s approach to rounding seems pretty haphazard here...).
</div><div><br>&nbsp;</div><div>So since there&#39;s really no ambiguity about what MPF(float) should be, and since it&#39;s a computationally trivial operation to initialize an MPF from a float,&nbsp;you certainly want to allow MPF&#39;s to be initialized from floats. &nbsp;Admittedly, for initialization from a float *literal* there are still going to be some surprises for the unwary: &nbsp;with MPF precision set to 128 bits, MPF( 
1.1) is going to give a binary number that&#39;s an accurate representation of the decimal 1.1 to only 53 bits, not 128 bits.</div><span class="q" style="color: rgb(85, 0, 85); "><div><br>&nbsp;</div><blockquote class="gmail_quote" style="margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex">
The main issue here is what means the user if he calls MPF(2.3):<br><br>a) MPF(&quot;2.3&quot;)<br><br>b) MPF(&quot;2.2999999999999998&quot;)</blockquote><div><br>&nbsp;</div></span><div>All 3 of MPF(2.3), MPF(&quot;2.3&quot;) and MPF(&quot; 
2.29...998&quot;) should be different values. &nbsp;MPF(2.3) is the closest 53-bit binary floating point number to the decimal 2.3, padded out with zero bits to whatever the current MPF precision is. &nbsp;MPF(&quot;2.3&quot;) should ideally be the closest p-bit binary floating point number to the decimal 
2.3, where p is the current precision. &nbsp;But in fact, with the way that GMP works it seems that all that can be said is that MPF(&quot;2.3&quot;) is a (p+some_extra_bits) binary floating point number that&#39;s close (but not necessarily closest) to the decimal 
2.3. &nbsp;Similarly for MPF(&quot;2.29...998&quot;).</div><div><br>&nbsp;</div><div>By the way, I&#39;m wondering whether this discussion really belongs on comp.lang.python instead...</div><div><br>&nbsp;</div><div>Mark</div></div>