Slight optimization in rational switching functions

* Better algorithm for int powers
* Simplification when 2*N=M (which is the usual case)
Merge branch 'v2.0'