title: Getting the fractional part of a float without using modf()
body: <p>I'm developing for a platform without a math library, so I need to build my own tools. My current way of getting the fraction is to convert the float to fixed point (multiply with (float)0xFFFF, cast to int), get only the lower part (mask with 0xFFFF) and convert it back to a float again.</p>
  
  <p>However, the imprecision is killing me. I'm using my Frac() and InvFrac() functions to draw an anti-aliased line. Using <code>modf</code> I get a perfectly smooth line. With my own method pixels start jumping around due to precision loss.</p>
  
  <p>This is my code:</p>
  
  <pre><code>const float fp_amount = (float)(0xFFFF);
  const float fp_amount_inv = 1.f / fp_amount;
  
  inline float Frac(float a_X)
  {
      return ((int)(a_X * fp_amount) &amp; 0xFFFF) * fp_amount_inv;
  }
  
  inline float Frac(float a_X)
  {
      return (0xFFFF - (int)(a_X * fp_amount) &amp; 0xFFFF) * fp_amount_inv;
  }
  </code></pre>
  
  <p>Thanks in advance!</p>