Fixed #5040 - simplify more math functions.