...
Run Format

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

View as plain text