Why is this combination of nearest-integer functions --- surprisingly --- continuous? Alright, I didn't know the best way to formulate my question. Basically, whilst doing some physics research, I naturally came upon the function
$$ f(x) = 2x[x] - [x]^2 $$
where I use $[x]$ as notation for the `nearest-integer function' (i.e. rounding off). Usually this function has to have a caveat of how we exactly define the value for $x \in \frac{1}{2} \mathbb Z$, but interestingly for this function it does not matter, since it turns out to be continuous! In fact, it turns out $f(x)$ is exactly given by the glued function of taking all the tangent lines of $x^2$ at integer values of $x$:

(Note: due to properties of $x^2$, the tangent lines exactly intersect at half-integer values of $x$.)
So my question is not literally `why is it continuous?', but rather: considering it is continuous, and considering that that is not a generic property of functions which are defined in terms of nearest-integer functions, is there a better (i.e. more insightful) way of expressing $f(x)$? Relatedly, is there some part of mathematics where functions similar to these naturally arise?

The difference between the rounding function (piecewise constant) and $x$ is a triangle wave, i.e. piecewise linear, periodic, ranging in $[-\frac12,\frac12)$.
If you square it, you get a continuous, piecewise quadratic function. This is enough to explain your observation.

