Imagine a vertical number line, and put x at a point in the middle. Then the next point above and below x are the “caps” for x, ceiling and floor (respectively).

^ ^
| |
+ ceil(x) + 6
| |
+ x . 5.7
| |
+ floor(x) + 5
| |
v v

This makes more sense with real numbers (decimals), when x is desired to be an integer. For example, merge sort partitions the array and we need integers for the indices. You can’t get the 5.5th index of a number, although you might get that dividing an 11-element array.

### Like this:

Like Loading...

*Related*