When I consider the absolute value of $x$ as a function of $x$ is it right to write the following? $$|x|=\begin{cases} x\, ,\text{ if}\, x\geq 0\\ -x \, ,\text{ if}\,x\leq 0\end{cases}$$ Maybe it is stupid doubt but I have not understood if I can say that in $[0, \infty)$ I have $|x|=x$ and in $(-\infty,0]$ I have $|x|=-x$.
$\color{red}{So\,\, my\,\, question\,\,is:}$
is it right to include $0$ in both cases? Since many times also in books I have read $$|x|=\begin{cases} x\, ,\text{ if}\, x\geq 0\\
-x \, ,\text{ if}\,x< 0\end{cases}$$ so with the $0$ only in the first case.
I have interested to this fact since when I consider $\int_{-2}^1 |x|\, dx$ I would split into: $\int_{-2}^0 |x|\, dx+\int_0^1 |x|\, dx$ and I would say that in $[-2,0]$ I have $|x|=-x$ whereas in $[0,1]$ I have $|x|=x$.
1.- Since $|x|$ is continuos at $x=0$, no matter where you put the equal sign (or no matter if you put it in both sido, although it si a little bit ugly).
2.- For integration, recall that no matter what happens at the extrema of the intervales), if the function is continuous up to them.