TITLE: $\lim_{x \to +\infty} f(x), \lim_{x \to -\infty} f(x)$ both exist and are finite, $f$ uniformly continuous
QUESTION [5 upvotes]: Let $f: \mathbb{R} \to \mathbb{R}$ be continuous and suppose that $\lim_{x \to +\infty} f(x)$ and $\lim_{x \to -\infty} f(x)$ both exist and are finite. How do I show that $f$ is uniformly continuous?
The work that I have so far:
For convenience, call the limits $A$ and $B$. Fix $\epsilon > 0$. Then there exist $M, N \in \mathbb{R}$ such that $|f(x) - A| < \epsilon$ for any $x \le M$, and $|f(x) - B| < \epsilon$ for any $x \ge N$. Without loss of generality assume $M < N$. By Theorem $4.19$ in Rudin's Principles of Mathematical Analysis, $f$ is uniformly continuous on the compact set $[M, N]$. So there exists $\delta > 0$ such that $|f(x) - f(y)| < \epsilon$ for any $x, y \in [M, N]$ with $|x-y| < \delta$.
I am not so sure how to proceed from here on out...

REPLY [3 votes]: You are off to a pretty good start. Building off what you have, consider arbitrary reals $x, y$ with $|x - y| < \min\{\delta, N-M\}$. If $x, y \in [M, N]$, then $|f(x) - f(y)| < \epsilon$. Otherwise, if without loss of generality $x \le y$, then since $|x - y| < N-M$, we either have $x < M$ and $x < y < N$, or $y > N$ and $y > x > M$.
In the first case, we have $|f(x)-f(M)| < |f(x)-A|+|A-f(M)| < \epsilon+\epsilon$. Similarly, we have $|f(y)-f(M)| < 2\epsilon$ if $y<M$, and otherwise $|f(y)-f(M)| < \epsilon$ $($since $|M-y| < |x-y| < \delta)$. Thus $|f(x)-f(y)| \le |f(x)-f(M)|+|f(M)-f(y)| < 2\epsilon+\max\{2\epsilon,\epsilon\} = 4\epsilon$.
The second case is analogous $($concretely, for instance, it follows by taking $f'(t) = -f(t)$, $x' = -y$, $y' = -x$, $M' = -N$, $N' = -M$ in the first case$)$. Hence $|f(x)-f(y)| < 4\epsilon$ whenever $|x-y| < \min\{\delta,N-M\}$. Since $4\epsilon$ can take on any positive real value, we are done.