Finding a tricky composition of two piecewise functions I have a question about finding the formula for a composition of two piecewise functions. The functions are defined as follows:
$$f(x) =
\begin{cases}
2x+1,  & \text{if $x \le 0$} \\
x^2, & \text{if $x > 0$}
\end{cases}$$
$$g(x) =
\begin{cases}
-x,  & \text{if $x < 2$} \\
5, & \text{if $x \ge 2$}
\end{cases}$$
My main question lies in how to approach finding the formula for the composition $g(f(x))$. I have seen a couple of other examples of questions like this online, but the domains of each piecewise function were the same, so the compositions weren't difficult to determine. 
In this case, I have assumed that, in finding $g(f(x))$, one must consider only the domain of $f(x)$. Thus, I think it would make sense to test for individual cases: for example, I would try to find $g(f(x))$ when $x <= 0$. $g(f(x))$ when $x <= 0$ would thus be $-2x-1$, right? However, I feel like I'm missing something critical, because I'm just assuming that the condition $x < 2$ for $g(x)$ can just be treated as $x <= 0$ in this case. Sorry for my rambling, and many thanks for anyone who can help lead me to the solution.

$$
g(x) =
\begin{cases}
-x,  & \text{if $x < 2$} \\
5, & \text{if $x \ge 2$}
\end{cases}
$$
In finding $g(f(x))$ with $g$ defined as above, one should remember that
$$
g(f(x)) =
\begin{cases}
-x,  & \text{if $f(x) < 2$} \\
5, & \text{if $f(x) \ge 2$}
\end{cases}
$$
with $f(x)$, not $x$, being the thing about which one asks when it is $<2$ and when it is $\ge 2$.
(The calculus text by Salas and Hille had a problem like this that used to get assigned in every academic term by vast numbers of professors who taught the course to thousands of students.  And every time an hour would be spent answering the students questions about it, which in every case said something like "I didn't even know where to start", and that's an hour that could have been spent on something that would help the students understand calculus. It was an even worse waste of time and effort than what usually goes on in the kind of math courses where the students don't want to learn math.)
