summaryrefslogtreecommitdiff
path: root/src/lib/math/atan2.go
blob: 64bf21a9e76137e9ec4965f71a58ee3859440b16 (plain)
1
2
3
4
5
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
31
32
33
34
35
36
37
38
39
// 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

import	math "math"

/*
 *	atan2 discovers what quadrant the angle
 *	is in and calls atan.
 */

const
(
	pio2	= .15707963267948966192313216e1;
	pi	= .3141592653589793238462643383276e1;
)

export func
atan2(arg1, arg2 float64) float64
{
	var x float64;

	if arg1+arg2 == arg1 {
		if arg1 >= 0 {
			return pio2;
		}
		return -pio2;
	}
	x = atan(arg1/arg2);
	if arg2 < 0 {
		if x <= 0 {
			return x + pi;
		}
		return x - pi;
	}
	return x;
}