MCPcopy Index your code
hub / github.com/python/cpython / exp

Method exp

Lib/_pydecimal.py:3001–3074  ·  view source on GitHub ↗

Returns e ** self.

(self, context=None)

Source from the content-addressed store, hash-verified

2999 self._exp, self._is_special)
3000
3001 def exp(self, context=None):
3002 """Returns e ** self."""
3003
3004 if context is None:
3005 context = getcontext()
3006
3007 # exp(NaN) = NaN
3008 ans = self._check_nans(context=context)
3009 if ans:
3010 return ans
3011
3012 # exp(-Infinity) = 0
3013 if self._isinfinity() == -1:
3014 return _Zero
3015
3016 # exp(0) = 1
3017 if not self:
3018 return _One
3019
3020 # exp(Infinity) = Infinity
3021 if self._isinfinity() == 1:
3022 return Decimal(self)
3023
3024 # the result is now guaranteed to be inexact (the true
3025 # mathematical result is transcendental). There's no need to
3026 # raise Rounded and Inexact here---they'll always be raised as
3027 # a result of the call to _fix.
3028 p = context.prec
3029 adj = self.adjusted()
3030
3031 # we only need to do any computation for quite a small range
3032 # of adjusted exponents---for example, -29 <= adj <= 10 for
3033 # the default context. For smaller exponent the result is
3034 # indistinguishable from 1 at the given precision, while for
3035 # larger exponent the result either overflows or underflows.
3036 if self._sign == 0 and adj > len(str((context.Emax+1)*3)):
3037 # overflow
3038 ans = _dec_from_triple(0, '1', context.Emax+1)
3039 elif self._sign == 1 and adj > len(str((-context.Etiny()+1)*3)):
3040 # underflow to 0
3041 ans = _dec_from_triple(0, '1', context.Etiny()-1)
3042 elif self._sign == 0 and adj < -p:
3043 # p+1 digits; final round will raise correct flags
3044 ans = _dec_from_triple(0, '1' + '0'*(p-1) + '1', -p)
3045 elif self._sign == 1 and adj < -p-1:
3046 # p+1 digits; final round will raise correct flags
3047 ans = _dec_from_triple(0, '9'*(p+1), -p-1)
3048 # general case
3049 else:
3050 op = _WorkRep(self)
3051 c, e = op.int, op.exp
3052 if op.sign == 1:
3053 c = -c
3054
3055 # compute correctly rounded result: increase precision by
3056 # 3 digits at a time until we get an unambiguously
3057 # roundable result
3058 extra = 3

Callers 14

test_none_argsMethod · 0.95
expMethod · 0.45
rtFunction · 0.45
eiFunction · 0.45
iFunction · 0.45
rFunction · 0.45
PgFunction · 0.45
$gFunction · 0.45
test_binary_floatsMethod · 0.45
test_named_parametersMethod · 0.45
test_implicit_contextMethod · 0.45
testExpMethod · 0.45

Calls 13

_check_nansMethod · 0.95
_isinfinityMethod · 0.95
adjustedMethod · 0.95
getcontextFunction · 0.85
DecimalClass · 0.85
strFunction · 0.85
_dec_from_tripleFunction · 0.85
_WorkRepClass · 0.85
_dexpFunction · 0.85
EtinyMethod · 0.80
_shallow_copyMethod · 0.80
_set_roundingMethod · 0.80

Tested by 6

test_none_argsMethod · 0.76
test_binary_floatsMethod · 0.36
test_named_parametersMethod · 0.36
test_implicit_contextMethod · 0.36
testExpMethod · 0.36
test_exceptionsMethod · 0.36