In this section, we will cover topics such as large integers–in Python and the decimal
library. We will also take a look at an example of factoring a large number and then two challenges for you to solve.
Python can do multiplication and division–and a contented multiplication and division of arbitrarily large integers with complete precision:
If we have 1001
and then we calculate 1001
squared, we get the right answer, of course; and even if we take a number like 10**100 + 1
, it correctly gets that number a hundred places with a 1
at each end. Now, if we square that number, it again gets it correct, all the way to the one at each end.
So, for simple integer operations, Python's precision is unlimited. However, if we want to square root, we need to import a math
library:
The math
library does not keep any arbitrary number of places, as you can see in the preceding code. If we take 10 **100 + 1
and square it, then take the square...