go/src/lib/math/atan2.go

41 lines
617 B
Go
Raw Normal View History

2008-03-28 13:56:47 -07:00
// 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 atan2
import atan "atan"
export atan2
/*
atan2 discovers what quadrant the angle
is in and calls atan.
*/
const
(
pio2 = .15707963267948966192313216e1;
pi = .3141592653589793238462643383276e1;
)
func
atan2(arg1, arg2 double) double
{
var x double;
if arg1+arg2 == arg1 {
if arg1 >= 0 {
return pio2;
}
return -pio2;
}
x = atan.atan(arg1/arg2);
if arg2 < 0 {
if x <= 0 {
return x + pi;
}
return x - pi;
}
return x;
}