# Which function ($f$) is continuous nowhere but $|f(x)|$ is continuous everywhere?

Which function ($f$) is continuous nowhere but $|f(x)|$ is continuous everywhere?

I found this question here, the question seems much interesting but for obvious reason it is closed there, I was wondering how to derive such a function?

-
you should either put $|x|\to |f|$ or take any discontinuous $f$ as an answer –  Ilya Oct 24 '11 at 15:58
You might want to work this out for yourself, so here is a hint: take a non-zero constant function for $|f(x)|$ (which is what I think you must mean, with $f$ mapping real line to real line). Then you need to think of a way of constructing $f(x)$ so that it is discontinuous - how could you make it discontinuous at a point? How could you use that on enough points to make it discontinuous everywhere? –  Mark Bennet Oct 24 '11 at 16:00

You could take $$f(x)=\begin{cases}1&x\in \mathbb Q \\ -1&x\in\mathbb R\setminus\mathbb Q\end{cases}$$
I assume you meant that $x\mapsto|f(x)|$ should be continuous everywhere. That is true here because $|f(x)|=1$ for all $x$. Did you mean something else by "$|x|$ is continuous everywhere"? –  Henning Makholm Oct 24 '11 at 16:01
Also known as $f=2\cdot\chi_{\Bbb Q}-1,$ for those familiar with characteristic/indicator functions. –  Cameron Buie Dec 17 '13 at 0:56