Limits of piecewise functions