34
$\begingroup$

It's clear to me how these functions work on positive real numbers: you round up or down accordingly. But if you have to round a negative real number: to take $\,-0.8\,$ to $\,-1,\,$ then do you take the floor of $\,-0.8,\,$ or the ceiling?

That is, which of the following are true?

$$\lfloor-0.8\rfloor=-1$$

$$\text{or}$$ $$\lceil-0.8\rceil=-1$$

$\endgroup$
4
  • 22
    $\begingroup$ Look at the number line - Floor: Go to the next integer left of where you are. - Ceiling: Go to the next integer right of where you are. $\endgroup$
    – k.stm
    Mar 28, 2013 at 15:26
  • $\begingroup$ Lower limit: Lower than or equal to it. Upper bound: More than or equal to it. So, First one is right.! $\endgroup$
    – Inceptio
    Mar 28, 2013 at 15:26
  • $\begingroup$ @K.Stm. +1 beat me to it :) $\endgroup$
    – Tyler
    Mar 28, 2013 at 15:27
  • $\begingroup$ To almost any mathematician, it is obvious: $\lfloor -1.8\rfloor=-2$. I remember however bumping into a computer implementation that gave $\lfloor -1.8\rfloor=-1$. $\endgroup$ Mar 28, 2013 at 15:44

5 Answers 5

36
$\begingroup$

The first is the correct: you round "down" (i.e. the greatest integer LESS THAN $-0.8$).

In contrast, the ceiling function rounds "up" to the least integer GREATER THAN $-0.8 = 0$.

$$ \begin{align} \lfloor{-0.8}\rfloor & = -1\quad & \text{since}\;\; \color{blue}{\bf -1} \lt -0.8 \lt 0 \\ \\ \lceil {-0.8} \rceil & = 0\quad &\text{since} \;\; -1 \lt -0.8 \lt \color{blue}{\bf 0} \end{align}$$

In general, we must have that $$\lfloor x \rfloor \leq x\leq \lceil x \rceil\quad \forall x \in \mathbb R$$

And so it follows that $$-1 = \lfloor -0.8 \rfloor \leq -0.8 \leq \lceil -0.8 \rceil = 0$$


K.Stm's suggestion is a nice, intuitive way to recall the relation between the floor and the ceiling of a real number $x$, especially when $x\lt 0$. Using the "number line" idea and plotting $-0.8$ with the two closest integers that "sandwich" $-0.8$ gives us:

$\qquad\qquad$enter image description here

We see that the floor of $x= -0.8$ is the first integer immediately to the left of $-0.8,\;$ and the ceiling of $x= -0.8$ is the first integer immediately to the right of $-0.8$, and this strategy can be used, whatever the value of a real number $x$.

$\endgroup$
2
  • 3
    $\begingroup$ With a vertical number line you even have "above" for ceiling and "below" for floor... $\endgroup$
    – koalo
    Aug 27, 2017 at 11:31
  • 1
    $\begingroup$ This is really by convention of definition not intuition. Pivoting towards or away from zero also has its intuition and places where it is useful. floor(x)={-floor(-x) if x<0, floor(x) otherwise. $\endgroup$ Oct 14, 2021 at 15:21
9
$\begingroup$

Keep in mind that $\lfloor x \rfloor \le x \le \lceil x \rceil$, so it's the first one.

More precisely, for $x \in \Bbb{R}$, $$ \lfloor x \rfloor = \max \{ z \in \Bbb{Z} : z \le x \} $$ while $$ \lceil x \rceil = \min \{ z \in \Bbb{Z} : x \le z \}. $$

$\endgroup$
1
  • 1
    $\begingroup$ Again this does not have to be so. By convention or common definition. Other definitions define it as rounding towards or away from 0 $\endgroup$ Oct 14, 2021 at 15:27
5
$\begingroup$

The first one is true: $\lfloor x\rfloor\le x\le\lceil x\rceil$, no matter if $x$ is negative or not.

$\endgroup$
1
  • $\begingroup$ According to your definition. It could also be rounding towards or away from zero. $\endgroup$ Oct 14, 2021 at 15:26
0
$\begingroup$

When $x\in \mathbb{R}\setminus \mathbb{Z}$ ($x$ is not an integer):

$\lfloor-x\rfloor= -\lfloor x\rfloor - 1.$

When $x \in \mathbb{R}$:

$\lceil-x\rceil= -\lfloor x\rfloor.$

$\endgroup$
1
  • 3
    $\begingroup$ Don't you mean $\lfloor -x \rfloor=-\lceil x\rceil$? For example, what happens when $x$ is an integer, say $3$? $\endgroup$
    – mursalin
    Oct 11, 2015 at 18:16
-2
$\begingroup$

The correct answer is it depends how you define floor and ceil. You could define as shown here the more common way with always rounding downward or upward on the number line.

OR

Floor always rounding towards zero. Ceiling always rounding away from zero. E.g floor(x)=-floor(-x) if x<0, floor(x) otherwise

If gravity were reversed, the ceiling would become the floor. So from a physics standpoint the standard mathematical definition might be inadequate.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.