0

I'm working with 3 sides of a triangle and trying to calculate its angles.

Sides are: 1.897188816229867142483767540106223394680554191282313497376163666145520171949117215017130626257969751E187390 2.581860838579567156635129752756628333180547211519304101349352896375658141271175354632905314191897000E187390 7.887018047741869189641330167452593390204386705619074761135437798419392435689195792476852434487192986E187389

Note the E's.

Here is my code:-

angles = []
a=<number too big to put here>    
b=<number too big to put here>    
c=<number too big to put here>      
angles.append(degrees(acos((decimal.Decimal(b) ** 2 + decimal.Decimal(c) ** 2 - decimal.Decimal(a) ** 2) / (2 * decimal.Decimal(b) * decimal.Decimal(c)))))
angles.append(degrees(acos((decimal.Decimal(c) ** 2 + decimal.Decimal(a) ** 2 - decimal.Decimal(b) ** 2) / (2 * decimal.Decimal(c) * decimal.Decimal(a)))))
angles.append(degrees(acos((decimal.Decimal(a) ** 2 + decimal.Decimal(b) ** 2 - decimal.Decimal(c) ** 2) / (2 * decimal.Decimal(a) * decimal.Decimal(b)))))

The error I get is:-

Traceback (most recent call last):
  File "G:/Python Projects/perfectTriangle1/testangle.py", line 13, in <module>
angles.append(degrees(acos((decimal.Decimal(b) ** 2 + decimal.Decimal(c) ** 2 - decimal.Decimal(a) ** 2) / (2 * decimal.Decimal(b) * decimal.Decimal(c)))))
decimal.InvalidOperation: [<class 'decimal.InvalidOperation'>]

When I print a, b and c, Python shows them a inf (infinity), which is why I believe it's falling over. Too big.

Is there a way to work with numbers of this size in Python?

Added note: I did previous look at the suggested link/duplicate, but it unfortunately does not solve the issue with numbers of this size.

Markus
  • 665
  • 2
  • 9
  • 22
  • Possible duplicate of [Handling very large numbers in Python](https://stackoverflow.com/questions/538551/handling-very-large-numbers-in-python) – Thomas Dussaut Mar 18 '19 at 10:41
  • 6
    When you divie your number by 1E187389, you get normal numbers with just a very high precision, and this does not change the value of your angles. – Dominique Mar 18 '19 at 10:43
  • 2
    Yes, yes. To @Dominique listen. I guess the task you've been given is to make you consider how to solve the problem without needing the very large numbers in the computer and since triangles don't change their angles when reduced in size linearly, this probably is what the task giver intended you to do. – Alfe Mar 18 '19 at 10:45
  • Thanks for the suggestion of linearly down sizing the numbers, that'll do the trick :) – Markus Mar 18 '19 at 10:58
  • You should probably reconsider the whole approach. Having lenghts like 1E187390 does not look right, you should rather use lenght units appropiate for the problem. – Stop harming Monica Mar 18 '19 at 11:22
  • The values are part of a larger problem and need to be that size and accuracy. But for this small task of checking the angles, proportionally reducing the sides as Dominique suggested will work well. – Markus Mar 18 '19 at 11:25

0 Answers0