Post Reply 
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
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
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Tim Wesserman or Edward Shore - mathnovice - 03-15-2019, 10:44 PM
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



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