title: calculating relative position in array in c
body: <p>I have an array of integers.  The integers can be positive or negative, and there can be duplicates.
  I sort the array, low to high, using qsort. </p>
  
  <pre><code>int myArray[] = { -4, -2, 0, 1, 1, 3, 3, 3, 9, 14, 17, 24 };
  </code></pre>
  
  <p>I then want to find the relative position of one of the integers (X) in the array, so I divide the position (Y) of the integer by the size of the array (S), and subtract .5 from the result, so that the relative position is expressed on a scale from -.50 to .50.</p>
  
  <pre><code>double position = Y/S - .50;
  </code></pre>
  
  <p>I want the lowest value in the array (in this case, -4) to be -.50, and the highest value (in this case, 24)  to be .50?  This works for the lowest value in the array, but not the highest:</p>
  
  <pre><code>double lowPosition = 0/12 - .50;  // lowPosition = -.50 double
  
  highPosition = 11/12 - .50;  // highPosition = .42
  </code></pre>
  
  <p>Two questions:</p>
  
  <ol>
  <li><p>What is the correct way to calculate this so I end up with the low value equal to -.5 and the high value = .5?</p></li>
  <li><p>How can I accurately calculate the relative position of a value when there are duplicates?  Should I eliminate the duplicates and then use the same calculation (position/size - .5)?</p></li>
  </ol>