The current code implicitly assumes det(R) = 1. It is necessary to consider the case where det(R) = -1.