make gcd and lcm positive (fix #4810)