code: public static double sigmoid(double x) {
      if (x<0) {
        double num = Math.exp(x);
        return num / (1.0 + num);
      }
      else {
        double den = 1.0 + Math.exp(-x);
        return 1.0 / den;
      }
    }
docs: Compute the sigmoid function with mean zero.
  Care is taken to compute an accurate answer without
  numerical overflow. (Added by rajatr)
  
  @param x Point to compute sigmoid at.
  @return Value of the sigmoid, given by 1/(1+exp(-x))