I need to use python to calculate the logarithms of objects of the form
log( 1 - n0 - n1*1j)
where n0 and n1 are very small numbers ~ 1.0e-27 and 1j is the the imaginary number.
Using cmath.log gives the wrong answer
print cmath.log( 1.0 - 1e-27 - 1.0e-27j )
(5e-55-1e-27j)
Using mpmath I can obtain the correct result but only if I phrase the argument correctly
import mpmath as mp
mp.prec = 100
print mp.log( mp.mpc(1.0) - mp.mpc(0.00000000000000000000000001) - mp.mpc(real='0.0', imag='1.0e-27') )
gives
(-1.0000389695486766657204483072e-26 - 1.00000000000000000000000001e-27j)
(which is the correct answer) whereas
print mp.log( mp.mpc(0.99999999999999999999999999) - mp.mpc(real='0.0', imag='1.0e-27') )
gives
(5.0e-55 - 1.0e-27j)
What's going on here? Can I get the right answer just using cmath.log()?