2

What methods exist to divide two numbers that do not require comparison? I am particularly interested in the case where $n$ and $d$ are integers, and we want to find $q$ such that $n=qd+r$.

I have found a number of methods that do use comparisons, such as:

  • Division by repeated subtraction
    Subtract $d$ from $n$ until $n<0$, which clearly uses a comparison.

  • Egyption Division
    We try to guess the quotients binary decomposition by multiplying $d$ by powers of 2 and comparing if they are bigger or less than $n$.

The methods I have found that do satisfy my the no-comparison rule are:

  • Goldschmidt Division which uses the following recurrence relation to approximate division
    $a_{i+1} = a_i * r_i \quad a_0 = n \\ b_{i+1} = b_i * r_i \quad b_0 = d \\ r_{i+1} = 2 - b_i \quad r_0 \in (0, 1)$

  • Newton-Raphson Division which also uses a recurrence relation to compute
    $q = x_k$ where $k ≥ \left \lceil \log_2(log_{17} (n + 1)) \right \rceil$ and
    $x_{i+1} = 2x_i - dx_i^2$ with $x_0 \in (0, 1)$

What other division methods are there that don't rely on comparisons? and Are there any such methods that do not use approximation like the two above?

Another question asks about similar methods that don't "guess" $q$, but the answers there don't fit my criteria of minimal comparisons. Also, please correct me if I made any mistakes in describing the methods above.

  • The specific reason I ask is because I'm working with a system where addition, subtraction and multiplications are super fast, but bitwise operations and comparisons are painfully slow. I'm hoping there is a way to do $\lfloor a/b \rfloor$ efficiently in this environment. – 54 6F 6D Jun 02 '19 at 05:04
  • You're interested in methods that work with integers, but can they use intermediate floating point representations, or should they strictly stick to integers? I haven't yet checked the two methods you mentionned in details, but those look like they're intended for floating point numbers. – N.Bach Jun 03 '19 at 22:18
  • @n-bach Only integers. The reason I ask for methods other than Goldschmidt and Newton's method is because to simulate fractions in an integer environment, we have to do division anyway, eg. 0.500.50 = 5050/10000. – 54 6F 6D Jun 04 '19 at 19:17
  • 1
    I'm not sure I understand your point. Fractions (rational numbers?) are not the same as floating point numbers. Summarizing IEEE 754, you can encode non-integers numbers of the form $a\times 2^b$ by storing $a$ and $b$ in memory, where $a$ and $b$ are of course constrained to be (possibly $<0$) integers. Assuming you can perform integer addition/substraction/multiplication + bitwise operations, you can also perform addition/substraction/multiplication on these so-called floating point numbers. What can be more tricky, is computing the decimal expansion. – N.Bach Jun 04 '19 at 20:30
  • 1
    One reason I asked about floating point numbers, is that some environments may not have good support for floats, and using them results in slower performances (assuming you have alternatives). – N.Bach Jun 04 '19 at 20:40

0 Answers0