Source file 
src/math/atan2.go
     1  
     2  
     3  
     4  
     5  package math
     6  
     7  
     8  
     9  
    10  
    11  
    12  
    13  
    14  
    15  
    16  
    17  
    18  
    19  
    20  
    21  
    22  
    23  
    24  
    25  
    26  
    27  
    28  
    29  
    30  func Atan2(y, x float64) float64 {
    31  	if haveArchAtan2 {
    32  		return archAtan2(y, x)
    33  	}
    34  	return atan2(y, x)
    35  }
    36  
    37  func atan2(y, x float64) float64 {
    38  	
    39  	switch {
    40  	case IsNaN(y) || IsNaN(x):
    41  		return NaN()
    42  	case y == 0:
    43  		if x >= 0 && !Signbit(x) {
    44  			return Copysign(0, y)
    45  		}
    46  		return Copysign(Pi, y)
    47  	case x == 0:
    48  		return Copysign(Pi/2, y)
    49  	case IsInf(x, 0):
    50  		if IsInf(x, 1) {
    51  			switch {
    52  			case IsInf(y, 0):
    53  				return Copysign(Pi/4, y)
    54  			default:
    55  				return Copysign(0, y)
    56  			}
    57  		}
    58  		switch {
    59  		case IsInf(y, 0):
    60  			return Copysign(3*Pi/4, y)
    61  		default:
    62  			return Copysign(Pi, y)
    63  		}
    64  	case IsInf(y, 0):
    65  		return Copysign(Pi/2, y)
    66  	}
    67  
    68  	
    69  	q := Atan(y / x)
    70  	if x < 0 {
    71  		if q <= 0 {
    72  			return q + Pi
    73  		}
    74  		return q - Pi
    75  	}
    76  	return q
    77  }
    78  
View as plain text