Why can't my code handle very large numbers | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
4th Nov 2023, 11:47 AM
P A Arrchith Iyer
P A Arrchith Iyer - avatar
4 Answers
+ 6
What do you mean by very large? It can happily take 1 billion. If the number is too large you may eventually hit the limitation of the float data type. There is a trade-off between number of decimal digits and precision. The amount of memory to store a single number, is fixed. If you want more precise calculation, maybe you can try the decimal type. https://docs.python.org/3/library/decimal.html
4th Nov 2023, 11:56 AM
Tibor Santa
Tibor Santa - avatar
+ 2
As I said, it works better with the decimal type. https://code.sololearn.com/c65e59Jc2158/?ref=app It is correct up to 28 digit precision, because that is the default but it can be raised even further. You can figure out how, if you actually follow the link I gave before, and read it.
4th Nov 2023, 6:37 PM
Tibor Santa
Tibor Santa - avatar
+ 2
you can use sympy... import sympy def euler(n): print(sympy.N(sympy.E, n)) euler(2000)
5th Nov 2023, 1:17 AM
Bob_Li
Bob_Li - avatar
0
Yes it can handle 1 billion but it cannot handle 1 septillion ,by the way is there any way to increase the storage of the number
4th Nov 2023, 12:15 PM
P A Arrchith Iyer
P A Arrchith Iyer - avatar