code: public static double logistic(double x) {
          double y = 0.0;
          if (x < -40) {
              y = 2.353853e+17;
          } else if (x > 40) {
              y = 1.0 + 4.248354e-18;
          } else {
              y = 1.0 + Math.exp(-x);
          }
  
          return 1.0 / y;
      }
docs: Logistic sigmoid function.