negative base raised to fractional exponent

Karthik Gurusamy kar1107 at gmail.com
Wed Oct 17 01:15:37 CEST 2007


On Oct 16, 2:48 pm, schaefer... at gmail.com wrote:
> Does anyone know of an approximation to raising a negative base to a
> fractional exponent? For example, (-3)^-4.11111 since this cannot be
> computed without using imaginary numbers. Any help is appreciated.

Use complex numbers. They are part of python (no special modules
needed).
Just write your real number r, as r+0j

e.g. square-root of -4 is 2j

>>> (-4+0j)**(0.5)
(1.2246063538223773e-16+2j)         # real part is almost zero
>>>
>>> (-4.234324+0j)**(0.5)
(1.2599652164116278e-16+2.0577473119894969j)
>>> 2.0577473119894969j ** 2
(-4.234324+0j)
>>>


Karthik




More information about the Python-list mailing list