title: Division of big numbers
body: <p>I need some division algorithm which can handle big integers (128-bit).
  I've already asked how to do it via bit shifting operators. However, my current implementation seems to ask for a better approach</p>
  
  <p>Basically, I store numbers as two <code>long long unsigned int</code>'s in the format</p>
  
  <p><code>A * 2 ^ 64 + B</code> with <code>B &lt; 2 ^ 64</code>.</p>
  
  <p>This number is divisible by <code>24</code> and I want to divide it by <code>24</code>.</p>
  
  <p>My current approach is to transform it like</p>
  
  <pre><code>A * 2 ^ 64 + B     A             B
  --------------  = ---- * 2^64 + ----
        24           24            24
  
             A               A mod 24                    B         B mod 24
  = floor( ---- ) * 2^64 +  ---------- * 2^64 + floor( ---- ) +   ----------
             24               24.0                      24           24.0
  </code></pre>
  
  <p>However, this is buggy.</p>
  
  <p>(Note that floor is <code>A / 24</code> and that <code>mod</code> is <code>A % 24</code>. The normal divisions are stored in <code>long double</code>, the integers are stored in <code>long long unsigned int</code>.</p>
  
  <p>Since <code>24</code> is equal to <code>11000</code> in binary, the second summand shouldn't change something in the range of the fourth summand since it is shifted 64 bits to the left.</p>
  
  <p>So, if <code>A * 2 ^ 64 + B</code> is divisible by 24, and B is not, it shows easily that it bugs since it returns some non-integral number.</p>
  
  <p>What is the error in my implementation?</p>