# Function $f(x)$ on $\mathbb{R}$ that is discontinuous at every point, but |f(x)| is continuous on $\mathbb{R}$

I have been doing questions on continuity, and a thought occurred to me, I asked a friend and she said that no such function exists, but I said a function must exist, because it could be constructed precisely so it holds the properties in question, she asked me for an example and I have no idea how to generate one.

Function $f(x)$ on $\mathbb{R}$ that is discontinuous at every point, but $|f(x)|$ is continuous on $\mathbb{R}$

Does such a function exist?

Yes: let $f(x):=1$ if $x$ is rational and $f(x):=-1$ otherwise.
• @Katie, no, the largest value of $f$ is $1$. – IAmNoOne Apr 29 '14 at 22:15