code: private int locate(double x) {
          int ju, jm, jl;
  
          boolean ascnd = (xx[n - 1] >= xx[0]);
  
          jl = 0;
          ju = n - 1;
          while (ju - jl > 1) {
              jm = (ju + jl) >> 1;
              if (x >= xx[jm] == ascnd) {
                  jl = jm;
              } else {
                  ju = jm;
              }
          }
  
          cor = Math.abs(jl - jsav) <= dj;
          jsav = jl;
  
          return Math.max(0, Math.min(n - 2, jl));
      }
docs: Given a value x, return a value j such that x is (insofar as possible)
  centered in the subrange xx[j..j+m-1], where xx is the stored data. The
  returned value is not less than 0, nor greater than n-1, where n is the
  length of xx.