TITLE: Bounded function $f \colon \mathbb R \to\mathbb R$ that does not achieve absolute extremum
QUESTION [0 upvotes]: Find an example of a bounded function $f\colon \mathbb R \to \mathbb R$ that does not achieve an absolute minimum nor an absolute maximum on $\mathbb R$

How is this possible? If $f(x) = x$, it does not achieve an absolute min nor abs max on $\mathbb R$ (or does it?) but is the function bounded? If $f(x) = 5$ or any constant number in $\mathbb R$, has this function achieved abs min and abs max (abs min=abs max)? and Is this $f$ bounded? 
Please help me here. Thank you very much!

REPLY [4 votes]: An example to broaden your thinking:
$$f(x)=\begin {cases}\frac 12 & x \in \Bbb Z\\
x-\lfloor x \rfloor & x \not \in \Bbb Z \end {cases}$$
This is bounded between $0$ and $1$ but achieves neither.  It is not continuous, but we were not asked for that.  It is a fine function, delivering a single output for every input in the domain.  
Another, with a slightly different idea
$$f(x)=\begin {cases} 0&x \not \in \Bbb Z\\
1-2^{-x}&x \gt 0, x\in \Bbb Z\\
-1+2^x&x \lt 0, x \in \Bbb Z \end {cases}$$
On the positive side you have a series of points approaching $1$.  On the negative side you have a series of points approaching $-1$.  Neither is achieved.
{"set_name": "stack_exchange", "score": 0, "question_id": 2742446}