# Absolute function continuous implies function piecewise continuous?

I have a simple true/false question that I am not sure on how to prove it.

If $|f(x)|$ is continuous in $]a,b[$ then $f(x)$ is piecewise continuous in $]a,b[$

Anyone that can point me in the right direction or give a counterexample, even though I think it's true. Thanks in advance!

-
Hint: What happens if $f$ only takes the values $1$ and $-1$? –  Tobias Kildetoft Jan 24 '13 at 19:50
@Tobias So you think the statement is false? I don't see the problem with a function defined like this: \begin{cases} 1 & x <0\\-1 & x \geq 0\end{cases} –  tim_a Jan 24 '13 at 19:58
What I mean is that if $f$ only takes those two values, then $|f|$ is automatically continuous. But there are nowhere continuous functions with just those two values. –  Tobias Kildetoft Jan 24 '13 at 20:02
Ok, I think I understand what you mean. But the statement is in the other direction. If you already know that $|f|$ is continuous, does this imply that $f$ is piecewise continuous in any case. –  tim_a Jan 24 '13 at 20:07
No, what I mentioned gives you a way to construct a counter example. –  Tobias Kildetoft Jan 24 '13 at 20:08

Define $f(x)$ to be $1$ if $x$ is rational and $-1$ if $x$ is irrational. Now $f$ is not continuous anywhere, but $|f|$ is identically $1$ and thus continuous.