Search code examples
pythonpython-3.xnumericlargenumber

How to get value for 0.5^(5000) in Python3?


Current I want to calculate the value of a=0.5**5000. I knowa is very small value, but I need use a to multiply b, where b = 5000!, a very large value.

But when I calculate value of a=0.5^5000, the result is 0. Does anyone have a good method to solve this problem? Thanks!


Solution

  • Try the decimal module:

    >>> from decimal import Decimal
    >>> print(Decimal("0.5") ** 5000)
    7.079811261048172892385615159E-1506
    >>>