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.
|
|
|
|
|
|
2008-06-27 17:06:23 -07:00
|
|
|
package math
|
|
|
|
|
|
2008-11-19 16:14:31 -08:00
|
|
|
import "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.
|
|
|
|
|
*/
|
|
|
|
|
|
2009-01-20 14:40:40 -08:00
|
|
|
func Asin(arg float64) float64 {
|
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 {
|
2009-01-22 16:23:44 -08:00
|
|
|
return NaN();
|
2008-03-28 13:56:47 -07:00
|
|
|
}
|
|
|
|
|
|
2008-11-19 16:14:31 -08:00
|
|
|
temp = Sqrt(1 - x*x);
|
2008-03-28 13:56:47 -07:00
|
|
|
if x > 0.7 {
|
2009-01-15 19:11:32 -08:00
|
|
|
temp = Pi/2 - Atan(temp/x);
|
2008-03-28 13:56:47 -07:00
|
|
|
} else {
|
2008-11-19 16:14:31 -08:00
|
|
|
temp = Atan(x/temp);
|
2008-03-28 13:56:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if sign {
|
|
|
|
|
temp = -temp;
|
|
|
|
|
}
|
|
|
|
|
return temp;
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-20 14:40:40 -08:00
|
|
|
func Acos(arg float64) float64 {
|
2008-11-25 09:22:58 -08:00
|
|
|
if arg > 1 || arg < -1 {
|
2009-01-22 16:23:44 -08:00
|
|
|
return NaN();
|
2008-03-28 13:56:47 -07:00
|
|
|
}
|
2009-01-15 19:11:32 -08:00
|
|
|
return Pi/2 - Asin(arg);
|
2008-03-28 13:56:47 -07:00
|
|
|
}
|