Source file src/pkg/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 Asin(x float64) float64 { 20 if x == 0 { 21 return x // special case 22 } 23 sign := false 24 if x < 0 { 25 x = -x 26 sign = true 27 } 28 if x > 1 { 29 return NaN() // special case 30 } 31 32 temp := Sqrt(1 - x*x) 33 if x > 0.7 { 34 temp = Pi/2 - satan(temp/x) 35 } else { 36 temp = satan(x / temp) 37 } 38 39 if sign { 40 temp = -temp 41 } 42 return temp 43 } 44 45 // Acos returns the arccosine of x. 46 // 47 // Special case is: 48 // Acos(x) = NaN if x < -1 or x > 1 49 func Acos(x float64) float64 { return Pi/2 - Asin(x) }