I want to know summation of some small numbers, such as {e^-1000, -e^1001, e^1002...}

If all numbers are positive, I can use log-sum-exp algorithm. But unfortunately, negative numbers are also included in numbers.

Is there any method to calculate the sum of such numbers?

  • $\begingroup$ You can (sort of) take the log of a negative number: $\log(-1) = i\pi$ (sort of) $\endgroup$
    – wlad
    Commented Dec 11, 2020 at 20:35
  • 2
    $\begingroup$ Maybe first all positive numbers can be summed up separately, and all negative summed up separately? $\endgroup$ Commented Dec 11, 2020 at 20:38
  • $\begingroup$ Defining $\log(-x) = \log(x) + i\pi$ and $\log(0)= \infty$ should present one solution to your problem $\endgroup$
    – wlad
    Commented Dec 11, 2020 at 20:41

1 Answer 1


In terms of Python, use

from cmath import log, exp

def clog(x):
    if  x == 0:
        return -float('inf')
        return log(x)

For a negative value of $x$, this gives $\log(x) = \log(-x) + i \pi$, and for $\log(0)$, this gives $\infty$.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.