TITLE: $f$ not measurable, but $\lvert f\rvert$ measurable
QUESTION [5 upvotes]: Do you know an example of a function $f\colon\mathbb{R}\to\mathbb{R}$ which is not $\mathcal{B}$-measurable but $\lvert f\rvert$ is $\mathcal{B}$-measurable?

REPLY [13 votes]: Pick any non-measurable set $A$. Define:
$$
f(x) = \begin{cases}
1 &: x \in A \\
-1 &: x \not\in A
\end{cases}
$$
$|f| = 1$ is a constant function, hence measurable. $f$ is easily seen to be non-measurable.