3501 | | """ |
3502 | | cdef RealNumber x |
3503 | | if not PY_TYPE_CHECK(self, RealNumber): |
3504 | | return self.__pow__(float(exponent)) |
3505 | | if not PY_TYPE_CHECK(exponent, RealNumber): |
3506 | | try: |
3507 | | x = self |
3508 | | exponent = x._parent(exponent) |
3509 | | except TypeError: |
3510 | | try: |
3511 | | return exponent.parent()(self)**exponent |
3512 | | except AttributeError: |
3513 | | raise TypeError |
3514 | | return self.__pow(exponent) |
| 3503 | |
| 3504 | We see that trac ticket #10736 is fixed:: |
| 3505 | |
| 3506 | sage: 16^0.5 |
| 3507 | 4.00000000000000 |
| 3508 | sage: int(16)^0.5 |
| 3509 | 4.00000000000000 |
| 3510 | sage: (1/2)^2.0 |
| 3511 | 0.250000000000000 |
| 3512 | sage: [n^(1.5) for n in range(10)] |
| 3513 | [0.000000000000000, 1.00000000000000, 2.82842712474619, 5.19615242270663, 8.00000000000000, 11.1803398874989, 14.6969384566991, 18.5202591774521, 22.6274169979695, 27.0000000000000] |
| 3514 | sage: int(-2)^(0.333333) |
| 3515 | 0.629961522017056 + 1.09112272417509*I |
| 3516 | sage: int(0)^(1.0) |
| 3517 | 0.000000000000000 |
| 3518 | sage: int(0)^(0.0) |
| 3519 | 1.00000000000000 |
| 3520 | """ |
| 3521 | cdef RealNumber base, x |
| 3522 | cdef mpfr_rnd_t rounding_mode |
| 3523 | if PY_TYPE_CHECK(self, RealNumber): |
| 3524 | base = <RealNumber>self |
| 3525 | rounding_mode = (<RealField_class>base._parent).rnd |
| 3526 | x = base._new() |
| 3527 | _sig_on |
| 3528 | if PY_TYPE_CHECK(exponent, int): |
| 3529 | mpfr_pow_si(x.value, base.value, exponent, rounding_mode) |
| 3530 | elif PY_TYPE_CHECK(exponent, Integer): |
| 3531 | mpfr_pow_z(x.value, base.value, (<Integer>exponent).value, rounding_mode) |
| 3532 | elif PY_TYPE_CHECK(exponent, RealNumber): |
| 3533 | mpfr_pow(x.value, base.value, (<RealNumber>exponent).value, rounding_mode) |
| 3534 | else: |
| 3535 | _sig_off |
| 3536 | return bin_op(self, exponent, operator.pow) |
| 3537 | _sig_off |
| 3538 | if mpfr_nan_p(x.value): |
| 3539 | return base._complex_number_() ** exponent |
| 3540 | return x |
| 3541 | else: |
| 3542 | return bin_op(self, exponent, operator.pow) |