go/src/lib/math/asin.go

58 lines
848 B
Go
Raw Normal View History

2008-03-28 13:56:47 -07:00
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package math
import math "math"
2008-03-28 13:56:47 -07:00
/*
* asin(arg) and acos(arg) return the arcsin, arccos,
* respectively of their arguments.
*
* Arctan is called after appropriate range reduction.
*/
const
(
2008-07-08 20:48:41 -07:00
pio2 = .15707963267948966192313216e1
2008-03-28 13:56:47 -07:00
)
export func
2008-07-08 20:48:41 -07:00
asin(arg float64)float64
2008-03-28 13:56:47 -07:00
{
2008-07-08 20:48:41 -07:00
var temp, x float64;
2008-03-28 13:56:47 -07:00
var sign bool;
sign = false;
x = arg;
if x < 0 {
x = -x;
sign = true;
}
if arg > 1 {
2008-07-07 14:07:46 -07:00
return sys.NaN();
2008-03-28 13:56:47 -07:00
}
temp = sqrt(1 - x*x);
2008-03-28 13:56:47 -07:00
if x > 0.7 {
temp = pio2 - atan(temp/x);
2008-03-28 13:56:47 -07:00
} else {
temp = atan(x/temp);
2008-03-28 13:56:47 -07:00
}
if sign {
temp = -temp;
}
return temp;
}
export func
2008-07-08 20:48:41 -07:00
acos(arg float64)float64
2008-03-28 13:56:47 -07:00
{
if(arg > 1 || arg < -1) {
2008-07-07 14:07:46 -07:00
return sys.NaN();
2008-03-28 13:56:47 -07:00
}
return pio2 - asin(arg);
}