[issue41315] Add mathematical functions as wrappers to decimal.Decimal methods

Stefan Krah report at bugs.python.org
Thu Jul 16 18:19:57 EDT 2020


Stefan Krah <stefan at bytereef.org> added the comment:

The top level decimal.py that dispatches to either _decimal or
_pydecimal is pure Python.  So perhaps these applications could
add these methods themselves:


>>> import decimal
>>> def exp(x):
...     return x.exp()
... 
>>> decimal.exp = exp
>>> 
>>> from decimal import *
>>> exp(Decimal(2))
Decimal('7.389056098930650227230427461')


As you see, it is no big deal, but it feels a bit odd to have
some methods like exp() and sqrt() exposed in the top level.


We already have:

  Decimal.exp()

And:

  >>> c = getcontext()
  >>> c.exp(Decimal(2))
  Decimal('7.389056098930650227230427461')

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue41315>
_______________________________________


More information about the Python-bugs-list mailing list