OLD | NEW |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package math | 5 package math |
6 | 6 |
7 | 7 |
8 func sinus(x float64, quad int) float64 { | 8 func sinus(x float64, quad int) float64 { |
9 // Coefficients are #3370 from Hart & Cheney (18.80D). | 9 // Coefficients are #3370 from Hart & Cheney (18.80D). |
10 const ( | 10 const ( |
(...skipping 27 matching lines...) Expand all Loading... |
38 | 38 |
39 if quad&1 != 0 { | 39 if quad&1 != 0 { |
40 y = 1 - y | 40 y = 1 - y |
41 } | 41 } |
42 if quad > 1 { | 42 if quad > 1 { |
43 y = -y | 43 y = -y |
44 } | 44 } |
45 | 45 |
46 yy := y * y; | 46 yy := y * y; |
47 temp1 := ((((P4*yy+P3)*yy+P2)*yy+P1)*yy + P0) * y; | 47 temp1 := ((((P4*yy+P3)*yy+P2)*yy+P1)*yy + P0) * y; |
48 » temp2 := ((((yy+Q3)*yy+Q2)*yy + Q1) * yy + Q0); | 48 » temp2 := ((((yy+Q3)*yy+Q2)*yy+Q1)*yy + Q0); |
49 return temp1 / temp2; | 49 return temp1 / temp2; |
50 } | 50 } |
51 | 51 |
52 // Cos returns the cosine of x. | 52 // Cos returns the cosine of x. |
53 func Cos(x float64) float64 { | 53 func Cos(x float64) float64 { |
54 if x < 0 { | 54 if x < 0 { |
55 x = -x | 55 x = -x |
56 } | 56 } |
57 return sinus(x, 1); | 57 return sinus(x, 1); |
58 } | 58 } |
59 | 59 |
60 // Sin returns the sine of x. | 60 // Sin returns the sine of x. |
61 func Sin(x float64) float64 { return sinus(x, 0) } | 61 func Sin(x float64) float64 { return sinus(x, 0) } |
OLD | NEW |