MCPcopy Index your code
hub / github.com/RustPython/RustPython / exp

Method exp

Lib/_pydecimal.py:2998–3071  ·  view source on GitHub ↗

Returns e ** self.

(self, context=None)

Source from the content-addressed store, hash-verified

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

Callers 9

test_none_argsMethod · 0.95
expMethod · 0.45
test_binary_floatsMethod · 0.45
test_named_parametersMethod · 0.45
test_implicit_contextMethod · 0.45
testExpMethod · 0.45
test_exceptionsMethod · 0.45
win_utils.pyFile · 0.45
powcFunction · 0.45

Calls 14

_check_nansMethod · 0.95
_isinfinityMethod · 0.95
adjustedMethod · 0.95
getcontextFunction · 0.85
DecimalClass · 0.85
lenFunction · 0.85
strFunction · 0.85
_dec_from_tripleFunction · 0.85
_WorkRepClass · 0.85
_dexpFunction · 0.85
EtinyMethod · 0.80
_shallow_copyMethod · 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