Consider a continuous function $f : \mathbb R \to \mathbb R$ such that $f(x)^2$ has a limit as $x\to\infty$. I am wondering if this implies the existence of the limit of $f(x)$ as $x\to\infty$.
One can easily conjure up discontinuous examples where the implication is not true (e.g. take $f$ to be $1$ on the rational numbers and $-1$ on the irrational numbers). However, I cannot seem to think of a situation where $f$ could fail to have a limit in the continuous case.
In fact, I was thinking of a proof along the following lines. Since $\limsup f^2 = \liminf f^2$, we must either have $\limsup f = \liminf f$ or $\limsup f = -\liminf f$. In the former case the limit of $f$ exists. In the latter case, $f$ also has a limit (equal to $0$) if $\limsup f = 0$, so consider $\limsup f > 0$. Then $f$ takes positive and negative values infinitely many times as $x \to \infty$, so necessarily $f$ also has a sequence of zeros going to infinity by the intermediate value theorem. This sequence of zeros is shared by $f^2$, and since this has a limit by assumption, we must have $f^2\to 0$ and consequently $f\to 0$.
Is this correct? I am mostly unsure about the first implication in the proof, i.e. that we must have $\limsup f = \pm\liminf f$.
If $f(x)^{2} \to 0$ then it is clear that $f(x) \to 0$. Suppose $f(x)^{2} \to a \neq 0$. Note that $f(x) $ does not vanish for large $x$ so it has to maintain the same sign after some stage. Can you finish?