title: Dealing with lack of floating point precision in OpenCL particle system
body: <p>I'm writing an OpenCL based particle system to speed up visualizations of large scale networks. In essence, this is a two phase problem where phase one applies negative gravity to each particle (typical n-bodies problem) so they all repel and phase two then attracts particles based on edges (or springs) between the particles.</p>
  
  <p>During each iteration of the gravity algorithm each particle's location, represented as a pair of floats, is impacted by the distance to each other particle (classical physics model, no drag, keeping it simple).</p>
  
  <p>In a situation where one has a perfectly spaced out square array of particles the application of gravity should result in symmetry across both the X and Y axes. This is true at the beginning of the gravity application, but over time the lack of precision inherent in adding together lots of floating point numbers results in small non-uniform deviations. This, in turn propagates through the entire n-body system and a loss of symmetry occurs.</p>
  
  <p>One simple way to avoid this is to use double precision numbers, however the GeForce 9600M GT on my MacBook Pro does not support double precision numbers. So, what's a nice way to deal with such problems in OpenCL? I've thought about truncating the floating point numbers I'm adding to a few decimals to avoid this problem, but that seems like a bit hokey.</p>