<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div>On Mar 8, 2014, at 13:01, "Mark H. Harris" <<a href="mailto:harrismh777@gmail.com">harrismh777@gmail.com</a>> wrote:</div><div><br></div><blockquote type="cite"><div dir="ltr"><br><br>On Saturday, March 8, 2014 2:16:00 PM UTC-6, Mark H. Harris wrote:<blockquote class="gmail_quote" style="margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir="ltr"><br><br>On Saturday, March 8, 2014 12:49:02 PM UTC-6, Mark Dickinson wrote:<div> </div><blockquote class="gmail_quote" style="margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div class="gmail_quote"><div>- if we're aiming to eliminate surprises, the 'fix' doesn't go far enough: Decimal(1.1 + 2.2) will still surprise, as will {snip}</div></div></div></div></blockquote><div><br></div></div></blockquote><div>How about this then: I think I've got it...</div><div><br></div><div>>>> ===== RESTART =========================</div><div>>>> from pdeclib import *</div><div>>>> d(1.1+2.2)</div><div>Decimal('3.3')</div><div>>>> sqrt(1.1+2.2)**2</div><div>Decimal('3.29999999999999999999999999999999999999999')</div><div>>>> x=d(1.1)</div><div>>>> y=d(2.2)</div><div>>>> sqrt(x+y)**2</div><div>Decimal('3.29999999999999999999999999999999999999999')</div><div>>>> </div><div><br></div><div>Code Below--------------------------</div><div> </div><div><div>#*****************************************************************/</div><div># sqrt(x) return decimal sqrt(x) rounded to context precision</div><div>#*****************************************************************/</div><div>def sqrt(x):</div><div> """ sqrt(x) square root function</div><div><br></div><div> (x may be string, int, float, or decimal)</div><div> (returns decimal rounded to context precision)</div><div> """</div><div> with localcontext(ctx=None) as cmngr:</div><div> cmngr.prec+=14</div><div> if (isinstance(x, float)==True):</div><div> y=x.__round__(15)</div><div> sqr=Decimal(repr(y)).sqrt()</div><div> else:</div><div> sqr=Decimal(x).sqrt()</div><div> return +sqr</div></div><div><br></div><div><div>-------------------- what say you? ---------------------</div></div></div></blockquote><br><div>It looks like you're trying to emulate a pocket calculator here. The question is, why are you accepting floats in the first place if that's your goal?</div></body></html>