Connection between ceil and round

87 Views Asked by At

I have two rounding functions.

The first is ceil, which always finds the smallest integer that is at least as large as the input. E.g. ceil(0) = 0, ceil(0.1) = 1, ceil(0.5) = 1, ceil(0.9) = 1.

The second is round, which always finds the integer closest to the input. For the middle (.5), it is defined as returning the next larger integer. E.g. round(0) = 0, round(0.1) = 0, round(0.5) = 1, round(0.9) = 1.

Is there a connection between them that allows to substitute ceil by round?

Like ceil(x) = g(round(f(x))) for some functions f, g that do not contain ceil? Do such functions exist?

I only care about nonnegative numbers as input for ceil and round.

2

There are 2 best solutions below

0
On BEST ANSWER

With the given rounding rule for half integers, your best bet is

$$\text{ceil}(x)=-\text{round}\left(-{1\over2}-x\right)$$

0
On

We have that $$\text {round}(x)=\text {ceil}\left(x-\frac {1}{2}\right)$$ But that rounds $.5$ down to $0$. If you want it to round up you have $$\text {round}(x)=\text {floor}\left(x+\frac {1}{2}\right)$$ We also have that $$\text {round}\left(x+\frac {1}{2}\right)=\text {ceil}(x)$$ But that assumes $.5$ rounds down.