Rounding Up to Next Odd Number

709 Views Asked by At

I want a function $f(x)$ that rounds any $x$ to the next odd integer. For example $f(5.5)=7,f(4)=5,f(7)=7$. It does not have to be continuous nor differentiable. When I say "function", I mean an explicit definition so I can graph it on graphing software (like Desmos). For example, something like $\mathbb{ceil}(\frac{x}{2})-1$ would be accepted, if it were right.

2

There are 2 best solutions below

0
On BEST ANSWER

You may define $f(x)=\lceil \frac{x+1}{2} \rceil \cdot 2 - 1$

1
On

If you want something that looks "mathematical" you can say $$f(x)=2\left\lceil \frac {x-1}2 \right\rceil +1$$