This is quite a useful one, as I've seen at least 3 different implementations of that. Rigorous tests for it were added as well. Refs #7772