4
$\begingroup$

While it is trivial to simply remove the fractional part of an irrational or rational number, and in programming I could just use the floor() or ceil() functions, I was wondering how such calculation is done using basic arithmetic.

In other words, how can I get the integer part of a (base-10) number using merely addition, subtraction, multiplication and division?

Perhaps this is trivial, but after a bit of trying and a bit of googling, I couldn't quite get my head around it. Maybe it is not so trivial after all?

  • 0
    I don't think that it can be done, because no member in the set of rational numbers, other than 0 and 1, has any privileged position under these operations.2012-11-21

2 Answers 2

8

It's impossible.

If you consider the set of all functions $P$ containing $f(x) = x$ and when $f,g \in P$ we have the sum $f(x)+g(x) \in P$, etc. then

Theorem $\text{floor}$ is not contained in $P$.

proof: We prove this by finding a property that everything in $P$ has but $\text{floor}$ does not. All functions in $P$ are continuous, but floor is not.

  • 0
    Division is continuous?2018-11-25
-1

It is possible to find the integer part of any number divided by two using basic arithmetic:

$\text{Floor}\left(\frac{n}{2}\right) = \frac{n}{2} - \frac{1}{4} + \frac{(-1)^n}{4}.$

I'm not aware of a solution for division by other numbers.

  • 1
    You mean any _integer_ divided by two.2014-08-23