Let $I \subseteq \mathbb{R}$ be an interval and $f: I \to \mathbb{R}$ a continuous function. We’ll say that $f$ is totally rational if the following propositions are true for any $x\in I$:
If $x \in \mathbb{Q}$ then $f(x) \in \mathbb{Q}$
If $f(x) \in \mathbb{Q}$ then $x \in \mathbb{Q}$
A simple example of such a function is the identity function $f(x)=x$. More generally any function of the form $f(x)=ax + b$ with $a,b\in \mathbb{Q}$ will do. Another class of functions that are totally rational are those of the form $$f(x)=\frac{ax + b}{cx + d}\qquad \text{with}\ a,b,c,d\in \mathbb{Q} \ \text{and}\ x\neq-\frac{d}{c}.$$
Besides functions of these kinds (and piecewise combinations thereof) I cannot find any other examples of such functions. It is easy to see, for instance, that any higher-order polynomial or rational function will fail condition (2).
But do other totally rational functions exist?