# Given a non-negative integer $m$ and a positive integer $n$, calculate $\lfloor \frac{m}{n} \rfloor$

Here is the problem:

• I have a non-negative integer $m$ and a positive integer $n$
• I would like to calculate $\lfloor \frac{m}{n} \rfloor$, $\lceil \frac{m}{n} \rceil$ and $m \bmod n$
• But I want to achieve this without using $floor$, $ceiling$, $round$, $modulo$, $abs$, and $if$

Now, if I find a way to calculate $\lfloor \frac{m}{n} \rfloor$, then the rest is easy:

• $\lceil \frac{m}{n} \rceil = \lfloor \frac{m+n-1}{n} \rfloor$
• $m \bmod n = m-\lfloor \frac{m}{n} \rfloor n$

Unfortunately, I haven't been able to do so as of yet.

Instead, I have found a way to calculate $\lceil \frac{m}{n} \rceil = \frac{m}{n}+\frac{1}{2}+\frac{\arctan(-\tan(\pi(\frac{m}{n}+\frac{1}{2})))}{\pi}$

So at this point, I am still left with the original problem of finding a way to calculate $\lfloor \frac{m}{n} \rfloor$, where the only progress towards a solution being the fact that I might be able to do so using $\lceil \frac{m}{n} \rceil$.

Please keep in mind that $\lceil \frac{m}{n} \rceil$ doesn't necessarily yield the correct output for negative values of $\frac{m}{n}$. In particular, it yields an incorrect output for negative integers, so I cannot use $\lfloor \frac{m}{n} \rfloor = \lceil \frac{m-n+1}{n} \rceil$.

Any ideas?

• Hello, I do not see why the formula you gave for [m/n] should work. Put m =n. LHS doesnt satisy RHS. I'm assuming that you want to get a closed form expression for it. – Sai Krishna Deep Apr 12 '14 at 9:01
• @Sai Krishna Deep: For $m=n$ the result is $1$, and since $\lceil 1 \rceil = 1$, I don't see any problem with this case. – barak manos Apr 12 '14 at 9:03
• And the right hand side is equal to $3/2 \neq 1$. – ah11950 Apr 12 '14 at 9:46
• @ah11950: both sides are equal to $1$! – barak manos Apr 12 '14 at 10:27
• Sorry, I missed the $1/2$ inside the tan...you are correct! – ah11950 Apr 12 '14 at 10:53