title: Getting -nan(ind) on double addition c++
body: <p>I am running into a problem when adding two doubles together, the variable startImpatience is a vector of double and the value of each element is initialized to 1.0 in the constructor of the class. 
  As soon as the line <code>startImpatience[id] += ((1.0 - dif) * dt)</code> is reached the value of the element gets value <code>-nan(ind)</code>.
  Here is the code snippet:</p>
  
  <pre><code>double pref_magnitude = sqrt((cPreferredVelocity[id].x * cPreferredVelocity[id].x) + (cPreferredVelocity[id].y * cPreferredVelocity[id].y));
  
  double magnitude = sqrt((cVelocity[id].x * cVelocity[id].x) + (cVelocity[id].y * cVelocity[id].y));
  
  double dif = pref_magnitude - magnitude / pref_magnitude;
  
  startImpatience[id] *= (1.0 - dt);
  // startImpatience[id] has a value
  
  startImpatience[id] += ((1.0 - dif) * dt);
  // startImpatience[id] is -nan(ind)
  </code></pre>
  
  <p>Every variable of which you don't see initialization, yes they are all of type double or vector of double.</p>
  
  <p>I cannot see what is wrong with the code, any help is greatly appreciated!</p>