private void boundEachRoot( double l , double u , int startIndex , int numRoots ) {

		// Find an upper and lower bound which contains one real root only
		int iter = 0;
		double allUpper = u;
		int root = 0;
		int lastFound = 0;
		double lastUpper = u;
		while( root < numRoots && iter++ < maxBoundIterations) {
			double m = (l+u)/2.0;
			int found = sturm.countRealRoots(l,m);
			// there are two
			if( found == 0 ) {
				l = m;
			} else if( found == 1 ) {
				bisectionRoot(l,m,startIndex + root++);
				l = m; u = lastUpper = allUpper;
				lastFound = 0;
				iter = 0;
			} else {
				lastFound = found;
				lastUpper = u = m;
			}
			if( l == u )
				throw new RuntimeException("Lower and upper bounds are the same");

			if( iter >= maxBoundIterations ) {
				// taking too long to bound these roots, probably multiple closely spaced roots
				// use the current best guess as a value for those roots
				for( int i = 0; i < lastFound; i++)
					roots[startIndex + root++ ] = m;
				l = lastUpper; u = lastUpper = allUpper;
				lastFound = 0;
				iter = 0;
			}
		}

		if( iter >= maxBoundIterations)
			throw new RuntimeException("Too many iterations finding upper and lower bounds");
	}
private void boundEachRoot ( double l , double u , int startIndex , int numRoots ) { int iter = 0 ; double allUpper = u ; int root = 0 ; int lastFound = 0 ; double lastUpper = u ; while ( root < numRoots && iter ++ < maxBoundIterations ) { double m = ( l + u ) / 2.0 ; int found = sturm . countRealRoots ( l , m ) ; if ( found == 0 ) { l = m ; } else if ( found == 1 ) { bisectionRoot ( l , m , startIndex + root ++ ) ; l = m ; u = lastUpper = allUpper ; lastFound = 0 ; iter = 0 ; } else { lastFound = found ; lastUpper = u = m ; } if ( l == u ) throw new RuntimeException ( "Lower and upper bounds are the same" ) ; if ( iter >= maxBoundIterations ) { for ( int i = 0 ; i < lastFound ; i ++ ) roots [ startIndex + root ++ ] = m ; l = lastUpper ; u = lastUpper = allUpper ; lastFound = 0 ; iter = 0 ; } } if ( iter >= maxBoundIterations ) throw new RuntimeException ( "Too many iterations finding upper and lower bounds" ) ; }
Finds a crude upper and lower bound for each root that includes only one root.

NOTE: Performance could be improved with better book keeping.  For example, if it knows a bound with
for two roots, then one for one root it then knows the bounds for both roots.