Computing a matrix function for exponential integrators