Ejemplo n.º 1
0
// Assumes uni-modal
std::pair<double,double> find_slice_boundaries_search(double& x0,slice_function& g,double logy,
						      double w,int m)
{
  // the initial point should be within the bounds, if the exist
  assert(not g.below_lower_bound(x0));
  assert(not g.above_upper_bound(x0));

  bool hit_lower_bound=false;
  bool hit_upper_bound=false;

  double gx0 = g(x0);

  double L = x0;
  double R = L;
  inc(R,w,g,hit_upper_bound);
  
  //  if (gx > logy) return find_slice_boundaries_stepping_out(x,g,logy,w,m,lower_bound,lower,upper_bound,upper);

  int state = -1;

  while(1)
  {
    double gL = g(L);
    double gR = g(R);

    if (gx0 < logy and gL > gx0) {
      x0 = L;
      gx0 = gL;
    }

    if (gx0 < logy and gR > gx0) {
      x0 = R;
      gx0 = gR;
    }

    // below bound, and slopes upwards to the right
    if (gR < logy and gL < gR) 
    {
      if (state == 2)
	break;
      else if (state == 1) {
	inc(R,w,g,hit_upper_bound);
	break;
      }

      state = 0;
      hit_lower_bound=false;
      L = R;
      inc(R,w,g,hit_upper_bound);
    }
    // below bound, and slopes upwards to the left
    else if (gL < logy and gR < gL) 
    {
      if (state == 2)
	break;
      if (state == 1)
      {
	dec(L,w,g,hit_lower_bound);
	break;
      }

      state = 1;
      hit_upper_bound=false;
      R = L;
      dec(L,w,g,hit_lower_bound);
    }
    else {
      state = 2;
      bool moved = false;
      if (gL >= logy and not hit_lower_bound) {
	moved = true;
	dec(L,w,g,hit_lower_bound);
      }

      if (gR >= logy and not hit_upper_bound) {
	moved = true;
	inc(R,w,g,hit_upper_bound);
      }

      if (not moved) break;
    }
  }

  return std::pair<double,double>(L,R);
}
int main(void) {
	printiln(inc());
	printiln(inc());
	printiln(inc());
	return 0;
}
Ejemplo n.º 3
0
	void build(T a[], const int n) {
		N = n;
		for (int i = 0; i < N; ++i) {
			inc(i, a[i]);
		}
	}
Ejemplo n.º 4
0
 Offset::Offset(const std::string& text)
 : line(0), column(0)
 {
   *this = inc(text.c_str(), text.c_str() + text.size());
 }
Ejemplo n.º 5
0
 Offset::Offset(const char* string)
 : line(0), column(0)
 {
   *this = inc(string, string + strlen(string));
 }
Ejemplo n.º 6
0
int bar(int arg) {
  if (arg > 42)
    return inc();
  return foo(val + arg);
}
Ejemplo n.º 7
0
int main(void) {
    int a = inc(5);
    a = function(a);
    return a;
}
Ejemplo n.º 8
0
void Motor::inc(){
  inc(STEP);
}
Ejemplo n.º 9
0
void Motor::goTo(int target, int s){
  if (throttle > target) dec(s);
  else if (throttle < target) inc(s);
}
Ejemplo n.º 10
0
void _add(int i) {
	inc(i);
	if (tot == 1) med = val[i];
	dist += abs(val[i] - med);
}
Ejemplo n.º 11
0
Archivo: buffer.hpp Proyecto: 6qat/fix8
    /** 
     *  Pop method: get the next value from the FIFO buffer.
     *
     *  \param data Pointer to the location where to store the 
     *  data popped from the buffer.
     */
    inline bool  pop(void ** data) {  /* modify only pread pointer */
        if (!data || empty()) return false;

        *data = buf[pread];
        return inc();
    } 
Ejemplo n.º 12
0
    static void btl(int s, int, BS &b) {
	if (poke(b,s)["Num"] == poke(b,s)["ItemArg"]) {
	    inc(turn(b,s)["CriticalRaise"], 2);
	}
    }
Ejemplo n.º 13
0
    static void btl(int s, int, BS &b) {
	inc(turn(b,s)["CriticalRaise"], 1);
    }
inline void Atomic::inc_ptr(volatile void*     dest) {
  inc((volatile jint*)dest);
}