A unified algorithm for elementary functions