Raises a to the power of b, to modulo if given. With two arguments, compute a**b. If a is negative then b must be integral. The result will be inexact unless b is integral and the result is finite and can be expressed exactly in 'precision' digits. With th
(self, a, b, modulo=None)
| 5117 | return a.__pos__(context=self) |
| 5118 | |
| 5119 | def power(self, a, b, modulo=None): |
| 5120 | """Raises a to the power of b, to modulo if given. |
| 5121 | |
| 5122 | With two arguments, compute a**b. If a is negative then b |
| 5123 | must be integral. The result will be inexact unless b is |
| 5124 | integral and the result is finite and can be expressed exactly |
| 5125 | in 'precision' digits. |
| 5126 | |
| 5127 | With three arguments, compute (a**b) % modulo. For the |
| 5128 | three argument form, the following restrictions on the |
| 5129 | arguments hold: |
| 5130 | |
| 5131 | - all three arguments must be integral |
| 5132 | - b must be nonnegative |
| 5133 | - at least one of a or b must be nonzero |
| 5134 | - modulo must be nonzero and have at most 'precision' digits |
| 5135 | |
| 5136 | The result of pow(a, b, modulo) is identical to the result |
| 5137 | that would be obtained by computing (a**b) % modulo with |
| 5138 | unbounded precision, but is computed more efficiently. It is |
| 5139 | always exact. |
| 5140 | |
| 5141 | >>> c = ExtendedContext.copy() |
| 5142 | >>> c.Emin = -999 |
| 5143 | >>> c.Emax = 999 |
| 5144 | >>> c.power(Decimal('2'), Decimal('3')) |
| 5145 | Decimal('8') |
| 5146 | >>> c.power(Decimal('-2'), Decimal('3')) |
| 5147 | Decimal('-8') |
| 5148 | >>> c.power(Decimal('2'), Decimal('-3')) |
| 5149 | Decimal('0.125') |
| 5150 | >>> c.power(Decimal('1.7'), Decimal('8')) |
| 5151 | Decimal('69.7575744') |
| 5152 | >>> c.power(Decimal('10'), Decimal('0.301029996')) |
| 5153 | Decimal('2.00000000') |
| 5154 | >>> c.power(Decimal('Infinity'), Decimal('-1')) |
| 5155 | Decimal('0') |
| 5156 | >>> c.power(Decimal('Infinity'), Decimal('0')) |
| 5157 | Decimal('1') |
| 5158 | >>> c.power(Decimal('Infinity'), Decimal('1')) |
| 5159 | Decimal('Infinity') |
| 5160 | >>> c.power(Decimal('-Infinity'), Decimal('-1')) |
| 5161 | Decimal('-0') |
| 5162 | >>> c.power(Decimal('-Infinity'), Decimal('0')) |
| 5163 | Decimal('1') |
| 5164 | >>> c.power(Decimal('-Infinity'), Decimal('1')) |
| 5165 | Decimal('-Infinity') |
| 5166 | >>> c.power(Decimal('-Infinity'), Decimal('2')) |
| 5167 | Decimal('Infinity') |
| 5168 | >>> c.power(Decimal('0'), Decimal('0')) |
| 5169 | Decimal('NaN') |
| 5170 | |
| 5171 | >>> c.power(Decimal('3'), Decimal('7'), Decimal('16')) |
| 5172 | Decimal('11') |
| 5173 | >>> c.power(Decimal('-3'), Decimal('7'), Decimal('16')) |
| 5174 | Decimal('-11') |
| 5175 | >>> c.power(Decimal('-3'), Decimal('8'), Decimal('16')) |
| 5176 | Decimal('1') |