title: Constrain function port from Arduino
body: <p>I'm now porting arduino code to stm32(c/c++). Please help me with <a href="http://arduino.cc/en/Reference/constrain" rel="nofollow">this</a> function:</p>
  
  <pre><code>constrain(x, a, b)
  </code></pre>
  
  <p><strong>Returns</strong></p>
  
  <p>x: if x is between a and b</p>
  
  <p>a: if x is less than a</p>
  
  <p>b: if x is greater than b</p>
  
  <p><strong>Example</strong></p>
  
  <pre><code>sensVal = constrain(sensVal, 10, 150);
  
  // limits range of sensor values to between 10 and 150 
  </code></pre>