In a document that I've seen, it says that if $f$ is defined on $\mathbb{R}$, then
$$|f(x)| = \begin{cases} f(x), & x \geq 0 \\ -f(x), & x < 0\text{.} \end{cases}$$
This is consistent with the definition of $|x|$ that I've seen, so I had no reason to believe this definition was wrong. But there's one thing that confuses me: if $f(x) = x^2$,
$$|x^{2}| = \begin{cases} x^{2}, & x \geq 0 \\ -x^{2}, & x < 0\text{.} \end{cases}$$ There's a problem here: if $x < 0$, $-x^2$ is clearly negative. Thus, there's something wrong with the definition of $|f(x)|$ I have above since $|f(x)| \geq 0$ for all $x$ (or at least, it should be that way).
What is it?