I have an expression like the following (anyway to input latex?),$$ z^{m}\left( \ln\left(\frac{z}{z-1}\right)-\sum_{k=1}^m \frac{z^{-k}}{k} \right)$$for m integer, z complexIt seems if I code it the following way, it gives noticeable round-off error in case $|z| \approx 1$.     Z_1=1/Z    ZV1=LOG(Z/(Z-1))    ZK=1.0_q    DO K=1,M;          ZK=ZK*Z_1      ZV1=ZV1-ZK/K    ENDDO    ZV1=ZV1/ZKAny suggestions on a better way to code this expression? Thanks,Added note:I have compared with gfortran built-in function Log and Mathematica NIntegrate the following two equivalent expressions,$$ \ln\left(\frac{z}{z-1}\right)$$and $$ \int_{0}^{1}\frac{1}{z-x} dx $$for $z$ to be complex, and found that these two can differ as big as $10^{-15}$ at small $|z|$. (I pushed NIntegrate to a PrecisionGoal of $10^{-17}$). This difference seems to be responsible for the error of the expression I was seeking help (I can upload a figure to support my claim made here if possible).Do you think this is likely the case? Which result should I trust, from the built-in function or from the numerically converged results? If use Taylor series to help improve numerical convergence, how to treat the case with $|z|\sim 1$, which does not validate any series expansion?Notes added:Besides the possibility that Mathematica didn't do a good enough job with Log function, it could equally be that NIntegrate does not reach the prescribed precision goal for some input z values. I am trying to clarify this issue with Mathematica and see how they respond.
what is the best way to code a formula to reduce roundoff error
numerical analysis;fortran