Tim Wesserman or Edward Shore
03-16-2019, 09:11 PM (This post was last modified: 03-16-2019 09:25 PM by Albert Chan.)
Post: #8
 Albert Chan Senior Member Posts: 1,995 Joined: Jul 2018
RE: Tim Wesserman or Edward Shore
I was curious what should be result of atan2(±0.0, ±0.0)

Below code based on Charles Petzold's blog: Atan2 and Exceptions (and why there aren't any)

Code:
from math import atan, pi, copysign def my_atan2(y, x):     if x>0: return atan(y/x)      if x<0: return atan(y/x) + copysign(pi, y)     if y: return copysign(pi/2, y)     if copysign(1,x) < 0: x = pi     return copysign(x, y)

z = 0.0
my_atan2(z,z) --> 0.0
my_atan2(-z,z) --> -0.0
my_atan2(z,-z) --> 3.14159
my_atan2(-z,-z) --> -3.14159
 « Next Oldest | Next Newest »

 Messages In This Thread Tim Wesserman or Edward Shore - mathnovice - 03-15-2019, 10:44 PM RE: Tim Wesserman or Edward Shore - chromos - 03-15-2019, 11:09 PM RE: Tim Wesserman or Edward Shore - Thomas Klemm - 03-16-2019, 02:20 AM RE: Tim Wesserman or Edward Shore - toml_12953 - 03-17-2019, 02:59 AM RE: Tim Wesserman or Edward Shore - ijabbott - 03-16-2019, 08:59 AM RE: Tim Wesserman or Edward Shore - JMB - 03-16-2019, 01:49 PM RE: Tim Wesserman or Edward Shore - Albert Chan - 03-16-2019 09:11 PM RE: Tim Wesserman or Edward Shore - mathnovice - 03-16-2019, 03:39 PM RE: Tim Wesserman or Edward Shore - SammysHP - 03-16-2019, 06:25 PM

User(s) browsing this thread: 1 Guest(s)