2014-12-22 Rüdiger Sonderfeld <ruediger@c-plusplus.de>
[official-gcc.git] / libgo / go / math / asin.go
blob46a5fe9d808793a2bb1734eaa86cf2d46e4dcd2f
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.
5 package math
7 /*
8 Floating-point arcsine and arccosine.
10 They are implemented by computing the arctangent
11 after appropriate range reduction.
14 // Asin returns the arcsine, in radians, of x.
16 // Special cases are:
17 // Asin(±0) = ±0
18 // Asin(x) = NaN if x < -1 or x > 1
20 //extern asin
21 func libc_asin(float64) float64
23 func Asin(x float64) float64 {
24 return libc_asin(x)
27 func asin(x float64) float64 {
28 if x == 0 {
29 return x // special case
31 sign := false
32 if x < 0 {
33 x = -x
34 sign = true
36 if x > 1 {
37 return NaN() // special case
40 temp := Sqrt(1 - x*x)
41 if x > 0.7 {
42 temp = Pi/2 - satan(temp/x)
43 } else {
44 temp = satan(x / temp)
47 if sign {
48 temp = -temp
50 return temp
53 // Acos returns the arccosine, in radians, of x.
55 // Special case is:
56 // Acos(x) = NaN if x < -1 or x > 1
58 //extern acos
59 func libc_acos(float64) float64
61 func Acos(x float64) float64 {
62 return libc_acos(x)
65 func acos(x float64) float64 {
66 return Pi/2 - Asin(x)