Tim Peters wrote: > [Raymond Hettinger] >>>>>from decimal import getcontext, Decimal as D >>>>>getcontext().prec = 3 >>>>>D('3.104') + D('2.104') >> >>Decimal("5.21") >> >>>>>D('3.104') + D('0.000') + D('2.104') >> >>Decimal("5.20") > > the results differ here because D(whatever) > ignores context settings; having a common operation ignore context is > ugly and error-prone). I don't see it's because of that. Even if D(whatever) didn't ignore the context settings, you'd get the same oddity if the numbers came from somewhere else with a different precision. I'm very uncomfortable about the whole idea of a context-dependent precision. It just seems to be asking for trouble. -- Greg Ewing, Computer Science Dept, +--------------------------------------+ University of Canterbury, | A citizen of NewZealandCorp, a | Christchurch, New Zealand | wholly-owned subsidiary of USA Inc. | greg.ewing at canterbury.ac.nz +--------------------------------------+
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4