TITLE: Composing two discontinuous functions into a continuous one
QUESTION [6 upvotes]: Please help me think of an example of two discontinuous functions on $\mathbb R$ whose composition gives a continuous function on $\mathbb R$.

REPLY [6 votes]: Hints for a general process of producing such functions:

The identity function $\mathrm{id}:\mathbb{R}\to\mathbb{R}$, defined by $\mathrm{id}(x)=x$, is continuous.
Think of two non-trivial functions on $\mathbb{R}$ that, when composed, give the identity.
Define $f$ and $g$ to be those functions, except only applied to some subset $S\subset\mathbb{R}$ (for example, the irrationals), defining them to be the identity on $\mathbb{R}\setminus S$. 

As long as the functions in step 2 map $S$ to itself, this (usually) produces discontinuous functions with the desired properties.
Some examples:

Choose the function "multiply by $-1$", apply it to any subset $S$ of $\mathbb{R}$ symmetric about the origin other than $\mathbb{R}$ itself.
Choose the function "take reciprocals", apply it to any subset $S$ of $\mathbb{R}\setminus\{0\}$ which is closed under taking reciprocals.