// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package math

// Atan2 returns the arc tangent of y/x, using
// the signs of the two to determine the quadrant
// of the return value.
//
// Special cases are (in order):
//
//	Atan2(y, NaN) = NaN
//	Atan2(NaN, x) = NaN
//	Atan2(+0, x>=0) = +0
//	Atan2(-0, x>=0) = -0
//	Atan2(+0, x<=-0) = +Pi
//	Atan2(-0, x<=-0) = -Pi
//	Atan2(y>0, 0) = +Pi/2
//	Atan2(y<0, 0) = -Pi/2
//	Atan2(+Inf, +Inf) = +Pi/4
//	Atan2(-Inf, +Inf) = -Pi/4
//	Atan2(+Inf, -Inf) = 3Pi/4
//	Atan2(-Inf, -Inf) = -3Pi/4
//	Atan2(y, +Inf) = 0
//	Atan2(y>0, -Inf) = +Pi
//	Atan2(y<0, -Inf) = -Pi
//	Atan2(+Inf, x) = +Pi/2
//	Atan2(-Inf, x) = -Pi/2
func (,  float64) float64 {
	if haveArchAtan2 {
		return archAtan2(, )
	}
	return atan2(, )
}

func (,  float64) float64 {
	// special cases
	switch {
	case IsNaN() || IsNaN():
		return NaN()
	case  == 0:
		if  >= 0 && !Signbit() {
			return Copysign(0, )
		}
		return Copysign(Pi, )
	case  == 0:
		return Copysign(Pi/2, )
	case IsInf(, 0):
		if IsInf(, 1) {
			switch {
			case IsInf(, 0):
				return Copysign(Pi/4, )
			default:
				return Copysign(0, )
			}
		}
		switch {
		case IsInf(, 0):
			return Copysign(3*Pi/4, )
		default:
			return Copysign(Pi, )
		}
	case IsInf(, 0):
		return Copysign(Pi/2, )
	}

	// Call atan and determine the quadrant.
	 := Atan( / )
	if  < 0 {
		if  <= 0 {
			return  + Pi
		}
		return  - Pi
	}
	return 
}