Refactored GMP and BC math functions