A weird function Consider this function $f:\mathbb{R}\to \mathbb{R}$: 
$$f(x):= \left\{\begin{array}{ll}
        (-1)^m\cdot 2^n & \text{for $x=\frac{2m+1}{2^n}$ with $n\in \mathbb{N}$, $m\in\mathbb{Z}$,}\\
        0 & \text{otherwise.} 
        \end{array}\right.
$$
Then, it is easy to show that
for all $a,b\in\mathbb{R}$, with $a<b$, we have 
$$\inf_{x\in (a,b)} f(x)=-\infty\quad\mbox{and} \sup_{x\in (a,b)} f(x)=+\infty.$$
My question (for which I do not have an answer) is about a stronger property.

Is there a function $f:\mathbb{R}\to \mathbb{R}$ such that for all $a,b\in\mathbb{R}$, with $a<b$, then $f((a,b))$ is dense in $\mathbb{R}$?

Any related references will be greatly appreciated.
 A: Yes: the Conway base-13 function. Under this function, the image of every nonempty open interval of $\Bbb R$ is not only dense in $\Bbb R$ but also the whole of $\Bbb R$.
A: Yes. 
Take an Hamel basis of $\mathbb R$ as a $\mathbb Q$ vector space. Write your basis $(b_i)_{i \in \mathbb R}$ and pick a special $b_j$. Now, let $\pi : \mathbb R \to \mathbb Qb_j \subset \mathbb R$ be the projection.
The graph of $\pi$ is dense in $\mathbb R^2$ so in particular your property is verified. 
Notice that $\pi$ looks strange but it is $\mathbb Q$-linear and periodic ! (And in fact, it has lot of periods : any $\mathbb Q$-linear combinaison of the $(b_i)_{i \in \mathbb R, i \neq j}$ will be a period for $\pi$ by definition)
A: This is based on Problem 113 in A. Shen & N. K. Vereshchagin, Basic Set Theory (AMS, 2002):
If $f$ is the function constructed in N.H.'s answer, it satisfies the condition
$$
f(x + y) = f(x) + f(y) \text{ for all } x, y \in \mathbb{R}.
$$
Any function satisfying this condition also satisfies $f(nx) = nf(x)$ for all $n \in \mathbb{Z}$. (In particular, $f(0) = 0$.) Therefore,
$f(qx) = qf(x)$ for all $q \in \mathbb{Q}$; that is, $f$ is $\mathbb{Q}$-linear.
On the other hand, the constructed $f$ is a non-zero function which assumes only
countably many values, so it cannot satisfy the condition $f(r) = rf(1)$ for all $r \in \mathbb{R}$; therefore $f$ is not $\mathbb{R}$-linear.
Now let $f: \mathbb{R} \to \mathbb{R}$ be any function that is $\mathbb{Q}$-linear but not $\mathbb{R}$-linear.
If $f$ were continuous on $\mathbb{R}$, it would be $\mathbb{R}$-linear.
If $f$ were continuous at $0$, it would be continuous everywhere.
So, $f$ is not continuous at $0$.
This implies that $f$ is unbounded in every open neighbourhood of $0$.

Proof: Suppose, on the contrary, that there existed $A > 0$, $\delta > 0$ such that $|f(x)| \leqslant A$ for all $x$ such that $|x| < \delta$.
[Incidentally, is it
  acceptable to write this phrase as "for all $|x| < \delta$"?]
Then for every positive integer $n$ we would have $|f(x)| = |f(nx)|/n \leqslant A/n$ for all $x$ such that $|x| < \delta/n$. This would imply that $f$ is continuous at $0$, contrary to what has been established.

For all $\delta > 0$, because $f$ is $\mathbb{Q}$-linear, $f((-\delta, \delta))$ is not only unbounded but also dense in $\mathbb{R}$.

Proof: Any finite open interval $V \subset \mathbb{R}$ is contained in $(-|f(x)|, |f(x)|)$ for some $x$ such that $|x| < \delta$. Then
  $$
f((-\delta, \delta)) \supseteq
f(\{qx : q \in \mathbb{Q},\ |q| < 1\}) =
\{qf(x) : q \in \mathbb{Q},\ |q| < 1\},
$$
  and this set is dense in $(-|f(x)|, |f(x)|)$, therefore it intersects $V$, as required.

For all $a, b \in \mathbb{R}$ such that $a < b$,
$$
f((a, b)) = \left\{
f\left(\frac{a + b}{2}\right) + y :
y \in f\left(\left(\frac{a - b}{2}, \frac{b - a}{2}\right)\right)
\right\},
$$
and this is dense in $\mathbb{R}$.
