Returns e ** self.
(self, context=None)
| 3044 | self._exp, self._is_special) |
| 3045 | |
| 3046 | def exp(self, context=None): |
| 3047 | """Returns e ** self.""" |
| 3048 | |
| 3049 | if context is None: |
| 3050 | context = getcontext() |
| 3051 | |
| 3052 | # exp(NaN) = NaN |
| 3053 | ans = self._check_nans(context=context) |
| 3054 | if ans: |
| 3055 | return ans |
| 3056 | |
| 3057 | # exp(-Infinity) = 0 |
| 3058 | if self._isinfinity() == -1: |
| 3059 | return _Zero |
| 3060 | |
| 3061 | # exp(0) = 1 |
| 3062 | if not self: |
| 3063 | return _One |
| 3064 | |
| 3065 | # exp(Infinity) = Infinity |
| 3066 | if self._isinfinity() == 1: |
| 3067 | return Decimal(self) |
| 3068 | |
| 3069 | # the result is now guaranteed to be inexact (the true |
| 3070 | # mathematical result is transcendental). There's no need to |
| 3071 | # raise Rounded and Inexact here---they'll always be raised as |
| 3072 | # a result of the call to _fix. |
| 3073 | p = context.prec |
| 3074 | adj = self.adjusted() |
| 3075 | |
| 3076 | # we only need to do any computation for quite a small range |
| 3077 | # of adjusted exponents---for example, -29 <= adj <= 10 for |
| 3078 | # the default context. For smaller exponent the result is |
| 3079 | # indistinguishable from 1 at the given precision, while for |
| 3080 | # larger exponent the result either overflows or underflows. |
| 3081 | if self._sign == 0 and adj > len(str((context.Emax+1)*3)): |
| 3082 | # overflow |
| 3083 | ans = _dec_from_triple(0, '1', context.Emax+1) |
| 3084 | elif self._sign == 1 and adj > len(str((-context.Etiny()+1)*3)): |
| 3085 | # underflow to 0 |
| 3086 | ans = _dec_from_triple(0, '1', context.Etiny()-1) |
| 3087 | elif self._sign == 0 and adj < -p: |
| 3088 | # p+1 digits; final round will raise correct flags |
| 3089 | ans = _dec_from_triple(0, '1' + '0'*(p-1) + '1', -p) |
| 3090 | elif self._sign == 1 and adj < -p-1: |
| 3091 | # p+1 digits; final round will raise correct flags |
| 3092 | ans = _dec_from_triple(0, '9'*(p+1), -p-1) |
| 3093 | # general case |
| 3094 | else: |
| 3095 | op = _WorkRep(self) |
| 3096 | c, e = op.int, op.exp |
| 3097 | if op.sign == 1: |
| 3098 | c = -c |
| 3099 | |
| 3100 | # compute correctly rounded result: increase precision by |
| 3101 | # 3 digits at a time until we get an unambiguously |
| 3102 | # roundable result |
| 3103 | extra = 3 |
no test coverage detected