summaryrefslogtreecommitdiff
path: root/libgo/go/math/atan.go
diff options
context:
space:
mode:
authorupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
committerupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
commit554fd8c5195424bdbcabf5de30fdc183aba391bd (patch)
tree976dc5ab7fddf506dadce60ae936f43f58787092 /libgo/go/math/atan.go
downloadcbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.bz2
cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.xz
obtained gcc-4.6.4.tar.bz2 from upstream website;upstream
verified gcc-4.6.4.tar.bz2.sig; imported gcc-4.6.4 source tree from verified upstream tarball. downloading a git-generated archive based on the 'upstream' tag should provide you with a source tree that is binary identical to the one extracted from the above tarball. if you have obtained the source via the command 'git clone', however, do note that line-endings of files in your working directory might differ from line-endings of the respective files in the upstream repository.
Diffstat (limited to 'libgo/go/math/atan.go')
-rw-r--r--libgo/go/math/atan.go62
1 files changed, 62 insertions, 0 deletions
diff --git a/libgo/go/math/atan.go b/libgo/go/math/atan.go
new file mode 100644
index 000000000..9d4ec2f72
--- /dev/null
+++ b/libgo/go/math/atan.go
@@ -0,0 +1,62 @@
+// 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
+
+/*
+ Floating-point arctangent.
+
+ Atan returns the value of the arctangent of its
+ argument in the range [-pi/2,pi/2].
+ There are no error returns.
+ Coefficients are #5077 from Hart & Cheney. (19.56D)
+*/
+
+// xatan evaluates a series valid in the
+// range [-0.414...,+0.414...]. (tan(pi/8))
+func xatan(arg float64) float64 {
+ const (
+ P4 = .161536412982230228262e2
+ P3 = .26842548195503973794141e3
+ P2 = .11530293515404850115428136e4
+ P1 = .178040631643319697105464587e4
+ P0 = .89678597403663861959987488e3
+ Q4 = .5895697050844462222791e2
+ Q3 = .536265374031215315104235e3
+ Q2 = .16667838148816337184521798e4
+ Q1 = .207933497444540981287275926e4
+ Q0 = .89678597403663861962481162e3
+ )
+ sq := arg * arg
+ value := ((((P4*sq+P3)*sq+P2)*sq+P1)*sq + P0)
+ value = value / (((((sq+Q4)*sq+Q3)*sq+Q2)*sq+Q1)*sq + Q0)
+ return value * arg
+}
+
+// satan reduces its argument (known to be positive)
+// to the range [0,0.414...] and calls xatan.
+func satan(arg float64) float64 {
+ if arg < Sqrt2-1 {
+ return xatan(arg)
+ }
+ if arg > Sqrt2+1 {
+ return Pi/2 - xatan(1/arg)
+ }
+ return Pi/4 + xatan((arg-1)/(arg+1))
+}
+
+// Atan returns the arctangent of x.
+//
+// Special cases are:
+// Atan(±0) = ±0
+// Atan(±Inf) = ±Pi/2
+func Atan(x float64) float64 {
+ if x == 0 {
+ return x
+ }
+ if x > 0 {
+ return satan(x)
+ }
+ return -satan(-x)
+}