code: public static float logSum(float[] logInputs) {
      int leng = logInputs.length;
      if (leng == 0) {
        throw new IllegalArgumentException();
      }
      int maxIdx = 0;
      float max = logInputs[0];
      for (int i = 1; i < leng; i++) {
        if (logInputs[i] > max) {
          maxIdx = i;
          max = logInputs[i];
        }
      }
      boolean haveTerms = false;
      double intermediate = 0.0f;
      float cutoff = max - SloppyMath.LOGTOLERANCE_F;
      // we avoid rearranging the array and so test indices each time!
      for (int i = 0; i < leng; i++) {
        if (i != maxIdx && logInputs[i] > cutoff) {
          haveTerms = true;
          intermediate += Math.exp(logInputs[i] - max);
        }
      }
      if (haveTerms) {
        return max + (float) Math.log(1.0 + intermediate);
      } else {
        return max;
      }
    }
docs: Returns the log of the sum of an array of numbers, which are
  themselves input in log form.  This is all natural logarithms.
  Reasonable care is taken to do this as efficiently as possible
  (under the assumption that the numbers might differ greatly in
  magnitude), with high accuracy, and without numerical overflow.
  
  @param logInputs An array of numbers [log(x1), ..., log(xn)]
  @return log(x1 + ... + xn)