1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
8 Floating-point arctangent.
10 Atan returns the value of the arctangent of its
11 argument in the range [-pi/2,pi/2].
12 There are no error returns.
13 Coefficients are #5077 from Hart & Cheney. (19.56D)
16 // xatan evaluates a series valid in the
17 // range [-0.414...,+0.414...]. (tan(pi/8))
18 func xatan(arg float64) float64 {
20 P4 = .161536412982230228262e2
21 P3 = .26842548195503973794141e3
22 P2 = .11530293515404850115428136e4
23 P1 = .178040631643319697105464587e4
24 P0 = .89678597403663861959987488e3
25 Q4 = .5895697050844462222791e2
26 Q3 = .536265374031215315104235e3
27 Q2 = .16667838148816337184521798e4
28 Q1 = .207933497444540981287275926e4
29 Q0 = .89678597403663861962481162e3
32 value := ((((P4*sq+P3)*sq+P2)*sq+P1)*sq + P0)
33 value = value / (((((sq+Q4)*sq+Q3)*sq+Q2)*sq+Q1)*sq + Q0)
37 // satan reduces its argument (known to be positive)
38 // to the range [0,0.414...] and calls xatan.
39 func satan(arg float64) float64 {
44 return Pi/2 - xatan(1/arg)
46 return Pi/4 + xatan((arg-1)/(arg+1))
49 // Atan returns the arctangent of x.
54 func Atan(x float64) float64 {