Need help in solving the problem of large numbers in Python, namely the division of large powers and factorials. Those. when trying to share conditional

(4 ** 512) / (5.5 ** 300) 

I get

 int too large to convert to float 

I tried to use decimal, but the problem remained:

 decimal.InvalidOperation: [<class 'decimal.DivisionImpossible'>] 

Similar problems when trying to divide large factorials:

 integer division result too large for a float 

    1 answer 1

    Try using Decimal :

     from decimal import Decimal print(Decimal(4 ** 512) / Decimal(5.5 ** 300)) # 1.399293161342312549090562061E+86 
    • It seems to understand what was the error - that is, decimal should be set before each number in the expression? - hitandfun pm
    • one
      or like this: print("{:>,.7f}".format(Decimal(4 ** 512) / Decimal(5.5 ** 300))) :) - S. Nick
    • Is there a default way for all numbers or variables to use decimal? - hitandfun
    • @hitandfun, this is not a separate object with its Decimal type, and ordinary integers and real numbers are an object with the type int and float - gil9red February