Half-integers are rounded to the nearest even integer.
Exercise: Write Round using only Floor, +, -, *, /,
... SPOILER SPACE ... ... SPOILER SPACE ... ... SPOILER SPACE ... ... SPOILER SPACE ... ... SPOILER SPACE ... ... SPOILER SPACE ... ... SPOILER SPACE ... ... SPOILER SPACE ... ... SPOILER SPACE ... ... SPOILER SPACE ... ... SPOILER SPACE ... ... SPOILER SPACE ... ... SPOILER SPACE ... ... SPOILER SPACE ... ... SPOILER SPACE ... ... SPOILER SPACE ... ... SPOILER SPACE ... ... SPOILER SPACE ... ... SPOILER SPACE ... ... SPOILER SPACE ... ... SPOILER SPACE ... ... SPOILER SPACE ... ... SPOILER SPACE ... ... SPOILER SPACE ... 0. I assume we are allowed constants too. 1. So we can (very familiarly) almost do it with floor(x+1/2). This rounds up all half-integers, whereas we need to round half of them down instead. 2. So it's wrong by the sum of an infinite stream of delta functions. 3. We can get an infinite stream of deltas, but not quite the right ones, by considering floor(x)+floor(-x) which is -1 except at integers where it's 0. Call this G(x). 4. So -1-G(x) is 0 except at integers where it's -1. 5. We need something that's mostly 0 except at 1/2, 5/2, ... so the correction we need is -1-G(x/2-1/4). Putting it together, we get floor(x+1/2) - floor(x/2-1/4) - floor(1/4-x/2) - 1. Two minutes of Python confirms this (well, actually two minutes of Python originally showed that I'd made a sign error, but I fixed it up). -- g