public static double noise(double x) {

      int bx0, bx1;
      double rx0, rx1, sx, t, u, v;
      t = x + N;
      bx0 = ((int) t) & M;
      bx1 = (bx0 + 1) & M;
      rx0 = t - (int) t;
      rx1 = rx0 - 1;

      sx = s_curve(rx0);
      u = rx0 * g1[p[bx0]];
      v = rx1 * g1[p[bx1]];

      return lerp(sx, u, v);
   }