OSDN Git Service

d67f32a50973c7a8c37e7cb65de50a7e574f70b6
[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 func libc_asin(float64) float64 __asm__("asin")
20 func Asin(x float64) float64 {
21         return libc_asin(x)
22 }
23
24 func asin(x float64) float64 {
25         if x == 0 {
26                 return x // special case
27         }
28         sign := false
29         if x < 0 {
30                 x = -x
31                 sign = true
32         }
33         if x > 1 {
34                 return NaN() // special case
35         }
36
37         temp := Sqrt(1 - x*x)
38         if x > 0.7 {
39                 temp = Pi/2 - satan(temp/x)
40         } else {
41                 temp = satan(x / temp)
42         }
43
44         if sign {
45                 temp = -temp
46         }
47         return temp
48 }
49
50 // Acos returns the arccosine of x.
51 //
52 // Special case is:
53 //      Acos(x) = NaN if x < -1 or x > 1
54 func libc_acos(float64) float64 __asm__("acos")
55 func Acos(x float64) float64 {
56         return libc_acos(x)
57 }
58
59 func acos(x float64) float64 {
60         return Pi/2 - Asin(x)
61 }