safe_cast: improve error message and implement the rational specialisation.