[Python-ideas] Re: Giving Decimal a global context was a mistake?

2022-04-08 Thread Greg Ewing
On 8/04/22 7:03 pm, Christopher Barker wrote: Are you SURE your accounting software is doing the right thing?  ;-) Well, I've only ever seen precision problems manifest themselves once, and that was when I wrote a script that used repeated multiplications by 10 as part of a process to convert

[Python-ideas] Re: Giving Decimal a global context was a mistake?

2022-04-08 Thread Christopher Barker
On Thu, Apr 7, 2022 at 2:51 PM Greg Ewing wrote: > I don't think it's entirely about the display. It's also about > things like sum([1/10] * 10) == 1 being False. sure, but: In [18]: sum([Decimal(1) / Decimal(3)] * 3) == Decimal(1) Out[18]: False Which is just as bad -- not as "confusing" to

[Python-ideas] Re: Giving Decimal a global context was a mistake?

2022-04-07 Thread Tim Peters
[David Mertz] >> Because the module implements >> http://speleotrove.com/decimal/decarith.html >> [Greg Ewing] > Well, yes, but someone made the decision to implement that > particular standard rather than one of the ones with fixed > precision. I'm

[Python-ideas] Re: Giving Decimal a global context was a mistake?

2022-04-07 Thread Tim Peters
[Greg Ewing ] > So can you elaborate on how you use variable precision? Numeric programmers frequently want this. An extreme example is in function `collision_stats()` in your Python distribution's Lib/test/support/__init__.py. This needs to compute the variance of a distribution for which we

[Python-ideas] Re: Giving Decimal a global context was a mistake?

2022-04-07 Thread Greg Ewing
On 8/04/22 6:01 am, David Mertz, Ph.D. wrote: Because the module implements http://speleotrove.com/decimal/decarith.html Well, yes, but someone made the decision to implement that particular standard rather than one of the ones with fixed

[Python-ideas] Re: Giving Decimal a global context was a mistake?

2022-04-07 Thread Greg Ewing
On 8/04/22 5:15 am, Christopher Barker wrote: I actually have almost the opposite position -- variable precision is the most useful part of the Decimal type ;-) So can you elaborate on how you use variable precision? Note the docs again: "End users typically would not expect 1.1 + 2.2 to

[Python-ideas] Re: Giving Decimal a global context was a mistake?

2022-04-07 Thread Marc-Andre Lemburg
On 07.04.2022 20:55, David Mertz, Ph.D. wrote: > On Thu, Apr 7, 2022 at 2:47 PM Marc-Andre Lemburg > wrote: > > In high finance, I've never seen decimals being used, only floats. > Excel is omnipresent, sets the standards and uses IEEE 754 floats > as well

[Python-ideas] Re: Giving Decimal a global context was a mistake?

2022-04-07 Thread David Mertz, Ph.D.
On Thu, Apr 7, 2022 at 2:47 PM Marc-Andre Lemburg wrote: > In high finance, I've never seen decimals being used, only floats. > Excel is omnipresent, sets the standards and uses IEEE 754 floats > as well (plus some black magic which sometimes helps, but often > makes things worse): > In forex,

[Python-ideas] Re: Giving Decimal a global context was a mistake?

2022-04-07 Thread Marc-Andre Lemburg
There's theory and math, and then there's reality. In reality, some accounting systems use decimals with fixed precision for certain aspects and apply predefined rounding (usually defined in the contracts between the counterparties or in accounting/tax regulations), while others use IEEE 754

[Python-ideas] Re: Giving Decimal a global context was a mistake?

2022-04-07 Thread Tim Peters
[Christopher Barker ] > So what does Decimal provide? Two things that you can't do with the built-in > (hardware) float: > > Variable precision > Control of rounding And a third: precisely defined results in base 10. You're thinking like an engineer, not an accountant ;-) Politicians don't know

[Python-ideas] Re: Giving Decimal a global context was a mistake?

2022-04-07 Thread David Mertz, Ph.D.
Because the module implements http://speleotrove.com/decimal/decarith.html On Thu, Apr 7, 2022 at 2:03 AM Greg Ewing wrote: > On 7/04/22 9:53 am, Chris Angelico wrote: > > how else would you do variable-precision in the standard library? > > Maybe the mistake was in thinking that we need

[Python-ideas] Re: Giving Decimal a global context was a mistake?

2022-04-07 Thread Chris Angelico
On Fri, 8 Apr 2022 at 03:16, Christopher Barker wrote: > I'm no accountant, but this strikes me as quite dangerous -- sure decimal > fractions are exact, but who says you are only doing decimal arithmetic? > Calculating interest, inflation, who knows what could easily introduce >

[Python-ideas] Re: Giving Decimal a global context was a mistake?

2022-04-07 Thread Christopher Barker
On Wed, Apr 6, 2022 at 11:03 PM Greg Ewing wrote: > Maybe the mistake was in thinking that we need variable > precision at all. > I actually have almost the opposite position -- variable precision is the most useful part of the Decimal type ;-) Warning: rant ahead: skip to the end for the

[Python-ideas] Re: Giving Decimal a global context was a mistake?

2022-04-07 Thread Marc-Andre Lemburg
On 07.04.2022 02:41, Greg Ewing wrote: > On 6/04/22 8:58 pm, Mark Dickinson via Python-ideas wrote: >> I'd be curious to know what alternatives you see. When a user writes `x + y` >> with both `x` and `y` instances of `decimal.Decimal`, the decimal module >> needs >> to know what precision to

[Python-ideas] Re: Giving Decimal a global context was a mistake?

2022-04-07 Thread Chris Angelico
On Thu, 7 Apr 2022 at 16:03, Greg Ewing wrote: > > On 7/04/22 9:53 am, Chris Angelico wrote: > > how else would you do variable-precision in the standard library? > > Maybe the mistake was in thinking that we need variable > precision at all. > > If the goal of Decimal was to provide arithmetic

[Python-ideas] Re: Giving Decimal a global context was a mistake?

2022-04-07 Thread Greg Ewing
On 7/04/22 9:53 am, Chris Angelico wrote: how else would you do variable-precision in the standard library? Maybe the mistake was in thinking that we need variable precision at all. If the goal of Decimal was to provide arithmetic that "works like your calculator", well, most calculators have

[Python-ideas] Re: Giving Decimal a global context was a mistake?

2022-04-06 Thread Greg Ewing
On 6/04/22 8:58 pm, Mark Dickinson via Python-ideas wrote: I'd be curious to know what alternatives you see. When a user writes `x + y` with both `x` and `y` instances of `decimal.Decimal`, the decimal module needs to know what precision to compute the result to (as well as what rounding mode

[Python-ideas] Re: Giving Decimal a global context was a mistake?

2022-04-06 Thread Chris Angelico
On Thu, 7 Apr 2022 at 07:41, Brendan Barnwell wrote: > > On 2022-04-06 14:28, Chris Angelico wrote: > > What do the specialized libraries offer that Decimal doesn't? Is it > > really worth all that hassle for the sake of teaching something that, > > in production, would just be done with floats

[Python-ideas] Re: Giving Decimal a global context was a mistake?

2022-04-06 Thread Brendan Barnwell
On 2022-04-06 14:28, Chris Angelico wrote: What do the specialized libraries offer that Decimal doesn't? Is it really worth all that hassle for the sake of teaching something that, in production, would just be done with floats and the math module anyway? If the decimal module did not already

[Python-ideas] Re: Giving Decimal a global context was a mistake?

2022-04-06 Thread Oscar Benjamin
On Wed, 6 Apr 2022 at 21:47, Chris Angelico wrote: > > On Thu, 7 Apr 2022 at 05:37, Oscar Benjamin > wrote: > > > > > > Not so obvious to me, as it would require inordinate amounts of > > > fiddling around when you want to dynamically adjust your precision. > > > You'd have to reassign every

[Python-ideas] Re: Giving Decimal a global context was a mistake?

2022-04-06 Thread Chris Angelico
On Thu, 7 Apr 2022 at 07:22, Oscar Benjamin wrote: > > On Wed, 6 Apr 2022 at 21:47, Chris Angelico wrote: > > > > On Thu, 7 Apr 2022 at 05:37, Oscar Benjamin > > wrote: > > > > > > > > Not so obvious to me, as it would require inordinate amounts of > > > > fiddling around when you want to

[Python-ideas] Re: Giving Decimal a global context was a mistake?

2022-04-06 Thread Chris Angelico
On Thu, 7 Apr 2022 at 05:37, Oscar Benjamin wrote: > > On Wed, 6 Apr 2022 at 17:48, Chris Angelico wrote: > > > > On Thu, 7 Apr 2022 at 02:17, Christopher Barker wrote: > > > > > > On Wed, Apr 6, 2022 at 5:11 AM Oscar Benjamin > > > wrote: > > >> > I'd be curious to know what alternatives you

[Python-ideas] Re: Giving Decimal a global context was a mistake?

2022-04-06 Thread Oscar Benjamin
On Wed, 6 Apr 2022 at 17:48, Chris Angelico wrote: > > On Thu, 7 Apr 2022 at 02:17, Christopher Barker wrote: > > > > On Wed, Apr 6, 2022 at 5:11 AM Oscar Benjamin > > wrote: > >> > I'd be curious to know what alternatives you see. When a user writes `x > >> > + y` with both `x` and `y`

[Python-ideas] Re: Giving Decimal a global context was a mistake?

2022-04-06 Thread Chris Angelico
On Thu, 7 Apr 2022 at 02:17, Christopher Barker wrote: > > On Wed, Apr 6, 2022 at 5:11 AM Oscar Benjamin > wrote: >> > I'd be curious to know what alternatives you see. When a user writes `x + >> > y` with both `x` and `y` instances of `decimal.Decimal`, the decimal >> > module needs to know

[Python-ideas] Re: Giving Decimal a global context was a mistake?

2022-04-06 Thread Christopher Barker
On Wed, Apr 6, 2022 at 5:11 AM Oscar Benjamin wrote: > > >Personally I think giving Decimal a global context was a mistake, [...] > I agree here -- though honestly, I think the benefits of Decimal are often misrepresented. Interestingly, the variable precision is the real bonus, not the decimal

[Python-ideas] Re: Giving Decimal a global context was a mistake?

2022-04-06 Thread Oscar Benjamin
On Wed, 6 Apr 2022 at 09:59, Mark Dickinson via Python-ideas wrote: > > Broken off from the "Custom literals, a la C++" thread: > > Greg Ewing wrote: > >Personally I think giving Decimal a global context was a mistake, [...] > > so arguing that "it's no worse than Decimal" isn't going to do much