Add/improve some new general math functions.

Merged Aaron Bray requested to merge feature/genericization into 4.x

Merge request reports