Exactness and optimality of methods for recovering functions from their spectrum