mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
redo and clean up math.
R=r DELTA=243 (60 added, 72 deleted, 111 changed) OCL=22909 CL=22912
This commit is contained in:
parent
293c8f8c65
commit
2c8d9a5619
12 changed files with 170 additions and 182 deletions
|
|
@ -4,37 +4,34 @@
|
|||
|
||||
package math
|
||||
|
||||
/*
|
||||
Coefficients are #3370 from Hart & Cheney (18.80D).
|
||||
*/
|
||||
const
|
||||
(
|
||||
sp0 = .1357884097877375669092680e8;
|
||||
sp1 = -.4942908100902844161158627e7;
|
||||
sp2 = .4401030535375266501944918e6;
|
||||
sp3 = -.1384727249982452873054457e5;
|
||||
sp4 = .1459688406665768722226959e3;
|
||||
sq0 = .8644558652922534429915149e7;
|
||||
sq1 = .4081792252343299749395779e6;
|
||||
sq2 = .9463096101538208180571257e4;
|
||||
sq3 = .1326534908786136358911494e3;
|
||||
|
||||
spiu2 = .6366197723675813430755350e0; // 2/pi
|
||||
)
|
||||
import "math"
|
||||
|
||||
func sinus(arg float64, quad int) float64 {
|
||||
// Coefficients are #3370 from Hart & Cheney (18.80D).
|
||||
const
|
||||
(
|
||||
P0 = .1357884097877375669092680e8;
|
||||
P1 = -.4942908100902844161158627e7;
|
||||
P2 = .4401030535375266501944918e6;
|
||||
P3 = -.1384727249982452873054457e5;
|
||||
P4 = .1459688406665768722226959e3;
|
||||
Q0 = .8644558652922534429915149e7;
|
||||
Q1 = .4081792252343299749395779e6;
|
||||
Q2 = .9463096101538208180571257e4;
|
||||
Q3 = .1326534908786136358911494e3;
|
||||
)
|
||||
x := arg;
|
||||
if(x < 0) {
|
||||
x = -x;
|
||||
quad = quad+2;
|
||||
}
|
||||
x = x * spiu2; /* underflow? */
|
||||
x = x * (2/Pi); /* underflow? */
|
||||
var y float64;
|
||||
if x > 32764 {
|
||||
var e float64;
|
||||
e, y = sys.modf(x);
|
||||
e = e + float64(quad);
|
||||
temsp1, f := sys.modf(0.25*e);
|
||||
temp1, f := sys.modf(0.25*e);
|
||||
quad = int(e - 4*f);
|
||||
} else {
|
||||
k := int32(x);
|
||||
|
|
@ -49,10 +46,10 @@ func sinus(arg float64, quad int) float64 {
|
|||
y = -y;
|
||||
}
|
||||
|
||||
ysq := y*y;
|
||||
temsp1 := ((((sp4*ysq+sp3)*ysq+sp2)*ysq+sp1)*ysq+sp0)*y;
|
||||
temsp2 := ((((ysq+sq3)*ysq+sq2)*ysq+sq1)*ysq+sq0);
|
||||
return temsp1/temsp2;
|
||||
yy := y*y;
|
||||
temp1 := ((((P4*yy+P3)*yy+P2)*yy+P1)*yy+P0)*y;
|
||||
temp2 := ((((yy+Q3)*yy+Q2)*yy+Q1)*yy+Q0);
|
||||
return temp1/temp2;
|
||||
}
|
||||
|
||||
export func Cos(arg float64) float64 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue