Jul-27-2018, 03:19 AM
If you are working with integers, you'll find that Python includes arbitrary precision integers. You generally want to avoid working with floats (what the math module generally does.) The following are useful for working with integers:
Disclaimer: I maintain gmpy2 when I have time.
>>> b=100 >>> a+b 12445 >>> a-b 12245 >>> a*b 1234500 >>> a/b # Floating point division in Python 3; varies in Python 2 123.45 >>> a//b # Integer division; in both Python 2 and 3 123 >>> a % b # Remainder 45 >>> divmod(a,b) # Returns both Integer division and Remainder (123, 45) >>> 2 ** 5 # Exponentiation 32While numpy is useful for many purposes, working with large numbers isn't its strong suit. Depending on what you want to do, you may want to use mpmath or gmpy2.
Disclaimer: I maintain gmpy2 when I have time.