<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div>On Jun 1, 2015, at 15:53, Nicholas Chammas <<a href="mailto:nicholas.chammas@gmail.com">nicholas.chammas@gmail.com</a>> wrote:</div><div><br></div><blockquote type="cite"><div><div dir="ltr"><div class="markdown-here-wrapper" style=""><p style="margin:0px 0px 1.2em!important">On Mon, Jun 1, 2015 at 6:15 PM Andrew Barnert <a href="http://mailto:abarnert@yahoo.com">abarnert@yahoo.com</a> wrote:</p>
<p style="margin:0px 0px 1.2em!important"></p><div class="markdown-here-exclude"><p></p><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><div>Obviously if you know the maximum precision needed before you start and explicitly set it to something big enough (or 7 places bigger than needed) you won't have any problem. <span style="background-color:rgba(255,255,255,0)">Steven chose a low precision just to make the problems easy to see and understand; he could just as easily have constructed examples for a precision of 18.</span><br></div></div><div dir="auto"><div><span style="background-color:rgba(255,255,255,0)"><br></span></div><div><span style="background-color:rgba(255,255,255,0)">Unfortunately, even in cases where it is both possible and sufficiently efficient to work out and set the precision high enough to make all of your calculations exact, that's not something most people know how to do reliably. In the fully general case, it's as hard as calculating error propagation.</span></div><div><br></div><div>As for the error: Python's decimal flags that too; the difference is that the flag is ignored by default. You can change it to warn or error instead. Maybe the solution is to make that easier--possibly just changing the docs. If you read the whole thing you will eventually learn that the default context ignores most such errors, but a one-liner gets you a different context that acts like SQL Server, but who reads the whole module docs (especially when they already believe they understand how decimal arithmetic works)? Maybe moving that up near the top would be useful?</div><div><br></div></div></blockquote><p></p></div><p style="margin:0px 0px 1.2em!important"></p>
<p style="margin:0px 0px 1.2em!important">This angle of discussion is what I was getting at when I wrote:</p>
<blockquote style="margin:1.2em 0px;border-left-width:4px;border-left-style:solid;border-left-color:rgb(221,221,221);padding:0px 1em;color:rgb(119,119,119);quotes:none">
<p style="margin:0px 0px 1.2em!important">Perhaps Python needs better rules for how precision and scale are affected by calculations (<a href="https://msdn.microsoft.com/en-us/library/ms190476.aspx">here are SQL Server’s</a>, for example), or better defaults when they are not specified?</p></blockquote></div></div></div></blockquote><div>I definitely agree that some edits to the decimal module docs, plus maybe a new HOWTO, and maybe some links to outside resources that explain things to people who are used to decimals in MSSQLServer or REXX or whatever, would be helpful. The question is, who has the sufficient knowledge, skill, and time/inclination to do it?</div><br><blockquote type="cite"><div><div dir="ltr"><div class="markdown-here-wrapper" style=""><blockquote style="margin:1.2em 0px;border-left-width:4px;border-left-style:solid;border-left-color:rgb(221,221,221);padding:0px 1em;color:rgb(119,119,119);quotes:none">
</blockquote>
<p style="margin:0px 0px 1.2em!important">It sounds like there are perhaps several improvements that can be made to how decimals are handled, documented, and configured by default, that could possibly address the majority of gotchas for the majority of people in a more user friendly way than can be accomplished with floats.</p>
<p style="margin:0px 0px 1.2em!important">For all the problems presented with decimals by Steven and others, I’m not seeing how overall they are supposed to be <em>worse</em> than the problems with floats.</p></div></div></div></blockquote><div>They're not worse than the problems with floats, they're the same problems... But the _effect_ of those problems can be worse, because:</div><div><br></div><div> * The magnitude of the rounding errors is larger.</div><div><br></div><div> * People mistakenly think they understand everything relevant about decimals, and the naive tests they try work out, so the problems may blindside them.</div><div><br></div><div> * Being much more detailed and configurable means the best solution may be harder to find.</div><div><br></div><div> * There's a lot of correct but potentially-misleading information out there. For example, any StackOverflow answer that says "you can solve this particular problem by using Decimal instead of float" can be very easily misinterpreted as applying to a much wider range of problems than it actually does.</div><div><br></div><div> * Sometimes performance matters.</div><div><br></div><div>On the other hand, the effect can also be less bad, because:</div><div><br></div><div> * Once people do finally understand a given problem, at least for many people and many problems, working out a solution is easier in decimal. For some uses (in particular, many financial uses, and some kinds of engineering problems), it's even trivial.</div><div><br></div><div> * Being more detailed and more configurable means the best solution may be better than any solution involving float.</div><div><br></div><div>I don't think there's any obvious answer to the tradeoff, short of making it easier for people to choose appropriately: a good HOWTO, decimal literals or Swift-style float-convertibles, making it easier to find/construct decimal64 or DECIMAL(18) or Money types, speeding up decimal (already done, but maybe more could be done), etc.</div><div><br></div><blockquote type="cite"><div dir="ltr"><div class="markdown-here-wrapper" style="">

<div title="MDH:PGRpdj5PbiBNb24sIEp1biAxLCAyMDE1IGF0IDY6MTUgUE0gQW5kcmV3IEJhcm5lcnQgJmx0O2Fi
YXJuZXJ0QHlhaG9vLmNvbSZndDsgd3JvdGU6PGJyPjwvZGl2PjxkaXYgY2xhc3M9ImdtYWlsX3F1
b3RlIj48YmxvY2txdW90ZSBjbGFzcz0iZ21haWxfcXVvdGUiIHN0eWxlPSJtYXJnaW46MCAwIDAg
LjhleDtib3JkZXItbGVmdDoxcHggI2NjYyBzb2xpZDtwYWRkaW5nLWxlZnQ6MWV4OyI+PGRpdiBk
aXI9ImF1dG8iPjxkaXY+T2J2aW91c2x5IGlmIHlvdSBrbm93IHRoZSBtYXhpbXVtIHByZWNpc2lv
biBuZWVkZWQgYmVmb3JlIHlvdSBzdGFydCBhbmQgZXhwbGljaXRseSBzZXQgaXQgdG8gc29tZXRo
aW5nIGJpZyBlbm91Z2ggKG9yIDcgcGxhY2VzIGJpZ2dlciB0aGFuIG5lZWRlZCkgeW91IHdvbid0
IGhhdmUgYW55IHByb2JsZW0uIDxzcGFuIHN0eWxlPSJiYWNrZ3JvdW5kLWNvbG9yOiByZ2JhKDI1
NSwgMjU1LCAyNTUsIDApOyI+U3RldmVuIGNob3NlIGEgbG93IHByZWNpc2lvbiBqdXN0IHRvIG1h
a2UgdGhlIHByb2JsZW1zIGVhc3kgdG8gc2VlIGFuZCB1bmRlcnN0YW5kOyBoZSBjb3VsZCBqdXN0
IGFzIGVhc2lseSBoYXZlIGNvbnN0cnVjdGVkIGV4YW1wbGVzIGZvciBhIHByZWNpc2lvbiBvZiAx
OC48L3NwYW4+PGJyPjwvZGl2PjwvZGl2PjxkaXYgZGlyPSJhdXRvIj48ZGl2PjxzcGFuIHN0eWxl
PSJiYWNrZ3JvdW5kLWNvbG9yOnJnYmEoMjU1LDI1NSwyNTUs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