github.com/primecitizens/pcz/std@v0.2.1/math/asin.go (about)

     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, in radians, of x.
    15  //
    16  // Special cases are:
    17  //
    18  //	Asin(±0) = ±0
    19  //	Asin(x) = NaN if x < -1 or x > 1
    20  func Asin(x float64) float64 {
    21  	return 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, in radians, of x.
    51  //
    52  // Special case is:
    53  //
    54  //	Acos(x) = NaN if x < -1 or x > 1
    55  func Acos(x float64) float64 {
    56  	return acos(x)
    57  }
    58  
    59  func acos(x float64) float64 {
    60  	return Pi/2 - Asin(x)
    61  }