libmath_func templates optimization stage 2