private int hunt(double x) {
        int jl = jsav, jm, ju, inc = 1;

        boolean ascnd = (xx[n - 1] >= xx[0]);

        if (jl < 0 || jl > n - 1) {
            jl = 0;
            ju = n - 1;
        } else {
            if (x >= xx[jl] == ascnd) {
                for (;;) {
                    ju = jl + inc;
                    if (ju >= n - 1) {
                        ju = n - 1;
                        break;
                    } else if (x < xx[ju] == ascnd) {
                        break;
                    } else {
                        jl = ju;
                        inc += inc;
                    }
                }
            } else {
                ju = jl;
                for (;;) {
                    jl = jl - inc;
                    if (jl <= 0) {
                        jl = 0;
                        break;
                    } else if (x >= xx[jl] == ascnd) {
                        break;
                    } else {
                        ju = jl;
                        inc += inc;
                    }
                }
            }
        }

        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));
    }
private int hunt ( double x ) { int jl = jsav , jm , ju , inc = 1 ; boolean ascnd = ( xx [ n - 1 ] >= xx [ 0 ] ) ; if ( jl < 0 || jl > n - 1 ) { jl = 0 ; ju = n - 1 ; } else { if ( x >= xx [ jl ] == ascnd ) { for ( ; ; ) { ju = jl + inc ; if ( ju >= n - 1 ) { ju = n - 1 ; break ; } else if ( x < xx [ ju ] == ascnd ) { break ; } else { jl = ju ; inc += inc ; } } } else { ju = jl ; for ( ; ; ) { jl = jl - inc ; if ( jl <= 0 ) { jl = 0 ; break ; } else if ( x >= xx [ jl ] == ascnd ) { break ; } else { ju = jl ; inc += inc ; } } } } 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 ) ) ; }
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.