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