where S+S={a+b∣a,b∈S} and g:[0,∞)∖(S+S)→S and h:(−∞,0)∖(S+S)→R are any functions.
To see that these functions work, note that for all x≥0 we have f(x)∈S, since if x∈S+S then x=a+b≥0 for some a,b∈S so f(x)=a+b∈S, and if x∈[0,∞)∖(S+S) then f(x)=g(x)∈S. So for all x,y≥0, f(x)+f(y)∈S+S and so f(f(x)+f(y))=f(x)+f(y) for all x,y≥0.
Now to show that all functions are of this form. Take S=f(R≥0). It’s easy to see that ∅=S⊆R, and that if a,b∈S with a+b≥0 then a+b∈S. Now for all x∈S+S, f(x)=x, for all x∈[0,∞)∖(S+S), we have f(x)∈S, and f is unconstrained elsewhere.