title: Better way than if else if else... for linear interpolation
body: <p>question is easy. 
  Lets say you have function</p>
  
  <pre><code>double interpolate (double x);
  </code></pre>
  
  <p>and you have a table that has map of known x-> y<br>
  for example<br>
   5    15<br>
   7    18<br>
   10   22<br>
  <strong>note:</strong> real tables are bigger ofc, this is just example. </p>
  
  <p>so for 8 you would return 18+((8-7)/(10-7))*(22-18)=19.3333333</p>
  
  <p>One cool way I found is 
  <a href="http://www.bnikolic.co.uk/blog/cpp-map-interp.html" rel="noreferrer">http://www.bnikolic.co.uk/blog/cpp-map-interp.html</a>
  (long story short it uses std::map, key= x, value = y for x->y data pairs).</p>
  
  <p>If somebody asks what is the if else if else way in title 
  it is basically:</p>
  
  <pre><code>if ((x&gt;=5) &amp;&amp; (x&lt;=7))
  {
  //interpolate
  }
  else 
       if((x&gt;=7) &amp;&amp; x&lt;=10)
       {
        //interpolate
       }
  </code></pre>
  
  <p>So is there a more clever way to do it or map way is the state of the art?  :)</p>
  
  <p>Btw I prefer soutions in C++  but obviously any language solution that has 1:1 mapping to C++ is nice.</p>