[issue46444] Wrong value of pi for larger values using math.cos() function

2022-01-20 Thread Darshan Kanade
Darshan Kanade added the comment: Thanks Mark, for the explanation. I had no idea about how the floating point values are represented as binary fractions in the computer hardware. It was a very informative document. Thanks again! -- nosy: -serhiy.storchaka _

[issue46444] Wrong value of pi for larger values using math.cos() function

2022-01-20 Thread Mark Dickinson
Mark Dickinson added the comment: Hi Darshan. This isn't a bug in Python. You're running into the limitations of floating-point arithmetic. There's a lot of good material on those limitations available on the web, starting with Python's own tutorial: https://docs.python.org/3/tutorial/float

[issue46444] Wrong value of pi for larger values using math.cos() function

2022-01-19 Thread Darshan Kanade
Darshan Kanade added the comment: The issue is that pi = k*math.cos(math.radians((90 - 180/k))) is giving wrong answer(289.384326...) for larger values of k, say k=2**62, but for smaller values say, k=100 it is giving correct answer(3.14) pi = k*math.sin(math.radians(180/k)) on the o

[issue46444] Wrong value of pi for larger values using math.cos() function

2022-01-19 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Yes, math.radians() just multiplies its argument by pi/180. And what is your issue? -- ___ Python tracker ___

[issue46444] Wrong value of pi for larger values using math.cos() function

2022-01-19 Thread Darshan Kanade
Change by Darshan Kanade : -- resolution: not a bug -> ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https

[issue46444] Wrong value of pi for larger values using math.cos() function

2022-01-19 Thread Darshan Kanade
Change by Darshan Kanade : -- status: closed -> open ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https://

[issue46444] Wrong value of pi for larger values using math.cos() function

2022-01-19 Thread Darshan Kanade
Darshan Kanade added the comment: In the program, I did convert degrees to radians So, this was what I used- 1)pi = k*math.cos(math.radians((90 - 180/k))) 2)pi = k*math.sin(math.radians(180/k)) where k=2**62 -- ___ Python tracker

[issue46444] Wrong value of pi for larger values using math.cos() function

2022-01-19 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Arguments of cos() and sin() should be in radians, not in degrees. So the correct formulas are k*cos(pi/2-pi/k) and k*sin(pi/k). They are useless because to find the pi approximation you need to know pi. -- nosy: +serhiy.storchaka resolution: -> n

[issue46444] Wrong value of pi for larger values using math.cos() function

2022-01-19 Thread Darshan Kanade
New submission from Darshan Kanade : I was solving this problem to find the approximate value of pi using the Archimedes method using two different logics - 1) The first one used the formula pi = k*cos(90-180/k) but when I gave very large input, say k=2**62 sides of polygon, then it gives the