diff options
Diffstat (limited to 'src/lib/math/asin.go')
-rw-r--r-- | src/lib/math/asin.go | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/src/lib/math/asin.go b/src/lib/math/asin.go new file mode 100644 index 000000000..6297064db --- /dev/null +++ b/src/lib/math/asin.go @@ -0,0 +1,60 @@ +// 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 asin + +import sys "sys" +import atan "atan" +import sqrt "sqrt" +export asin, acos + +/* + * asin(arg) and acos(arg) return the arcsin, arccos, + * respectively of their arguments. + * + * Arctan is called after appropriate range reduction. + */ + +const +( + pio2 = .15707963267948966192313216e1; +) + +func +asin(arg double)double +{ + var temp, x double; + var sign bool; + + sign = false; + x = arg; + if x < 0 { + x = -x; + sign = true; + } + if arg > 1 { + return sys.NaN(); + } + + temp = sqrt.sqrt(1 - x*x); + if x > 0.7 { + temp = pio2 - atan.atan(temp/x); + } else { + temp = atan.atan(x/temp); + } + + if sign { + temp = -temp; + } + return temp; +} + +func +acos(arg double)double +{ + if(arg > 1 || arg < -1) { + return sys.NaN(); + } + return pio2 - asin(arg); +} |