OSDN Git Service

PR go/52358
[pf3gnuchains/gcc-fork.git] / libgo / go / math / asin.go
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.
4
5 package math
6
7 /*
8         Floating-point arcsine and arccosine.
9
10         They are implemented by computing the arctangent
11         after appropriate range reduction.
12 */
13
14 // Asin returns the arcsine of x.
15 //
16 // Special cases are:
17 //      Asin(±0) = ±0
18 //      Asin(x) = NaN if x < -1 or x > 1
19
20 //extern asin
21 func libc_asin(float64) float64
22
23 func Asin(x float64) float64 {
24         return libc_asin(x)
25 }
26
27 func asin(x float64) float64 {
28         if x == 0 {
29                 return x // special case
30         }
31         sign := false
32         if x < 0 {
33                 x = -x
34                 sign = true
35         }
36         if x > 1 {
37                 return NaN() // special case
38         }
39
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)
45         }
46
47         if sign {
48                 temp = -temp
49         }
50         return temp
51 }
52
53 // Acos returns the arccosine of x.
54 //
55 // Special case is:
56 //      Acos(x) = NaN if x < -1 or x > 1
57
58 //extern acos
59 func libc_acos(float64) float64
60
61 func Acos(x float64) float64 {
62         return libc_acos(x)
63 }
64
65 func acos(x float64) float64 {
66         return Pi/2 - Asin(x)
67 }