title: Finding the index position of the nearest value in a Fortran array
body: <p>I have two sorted arrays, one containing factors (array <code>a</code>) that when multiplied with values from another array (array <code>b</code>), yields the desired value:</p>
  
  <pre><code>a(idx1) * b(idx2) = value
  </code></pre>
  
  <p>With <code>idx2</code> known, I would like find the <code>idx1</code> of <code>a</code> that provides the factor necessary to get as close to <code>value</code> as possible.</p>
  
  <p>I have looked at some different algorithms (<a href="https://stackoverflow.com/a/4431347/943773">like this one</a>, for example), but I feel like they would all be subject to potential problems with floating point arithmetic in my particular case.</p>
  
  <p>Could anyone suggest a method that would avoid this?</p>