Using the formula for the triangular numbers we note that if
$m \in I = [2n^2+n+1,2n^2+3n+1]$ for some $n=0,1,2,\ldots$ then $f(m)=m,$ otherwise
$f(m)=-m.$
The only possible choice of $n$ is $ \lfloor \sqrt{m/2} \rfloor,$ since if we write
$l(n) = 2n^2+n+1$ and $u(n) = 2n^2+3n+1$ by writing $\sqrt{m/2} = N + r,$ where $N$ is an integer and $0 \le r < 1$ we have
$$u \left( \lfloor \sqrt{m/2} \rfloor – 1 \right) = 2N^2 – N < 2N^2+4Nr+r^2 < m,$$
and so $m \notin I.$ Similarly
$$l \left( \lfloor \sqrt{m/2} \rfloor + 1 \right) > m,$$
so $m \notin I.$ Hence we have
$$f(m) = m \textrm{ when } m \in [2t^2+t+1,2t^2+3t+1] \textrm{ for }
t = \lfloor \sqrt{m/2} \rfloor,$$
otherwise $f(m)=-m.$