|
0
|
1 //=========================================================================== |
|
|
2 // |
|
|
3 // k_sin.c |
|
|
4 // |
|
|
5 // Part of the standard mathematical function library |
|
|
6 // |
|
|
7 //=========================================================================== |
|
|
8 //####COPYRIGHTBEGIN#### |
|
|
9 // |
|
|
10 // ------------------------------------------- |
|
|
11 // The contents of this file are subject to the Cygnus eCos Public License |
|
|
12 // Version 1.0 (the "License"); you may not use this file except in |
|
|
13 // compliance with the License. You may obtain a copy of the License at |
|
|
14 // http://sourceware.cygnus.com/ecos |
|
|
15 // |
|
|
16 // Software distributed under the License is distributed on an "AS IS" |
|
|
17 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the |
|
|
18 // License for the specific language governing rights and limitations under |
|
|
19 // the License. |
|
|
20 // |
|
|
21 // The Original Code is eCos - Embedded Cygnus Operating System, released |
|
|
22 // September 30, 1998. |
|
|
23 // |
|
|
24 // The Initial Developer of the Original Code is Cygnus. Portions created |
|
2
|
25 // by Cygnus are Copyright (C) 1998,1999 Cygnus Solutions. All Rights Reserved. |
|
0
|
26 // ------------------------------------------- |
|
|
27 // |
|
|
28 //####COPYRIGHTEND#### |
|
|
29 //=========================================================================== |
|
|
30 //#####DESCRIPTIONBEGIN#### |
|
|
31 // |
|
2
|
32 // Author(s): jlarmour |
|
|
33 // Contributors: jlarmour |
|
0
|
34 // Date: 1998-02-13 |
|
|
35 // Purpose: |
|
|
36 // Description: |
|
|
37 // Usage: |
|
|
38 // |
|
|
39 //####DESCRIPTIONEND#### |
|
|
40 // |
|
|
41 //=========================================================================== |
|
|
42 |
|
|
43 // CONFIGURATION |
|
|
44 |
|
|
45 #include <pkgconf/libm.h> // Configuration header |
|
|
46 |
|
|
47 // Include the Math library? |
|
|
48 #ifdef CYGPKG_LIBM |
|
|
49 |
|
|
50 // Derived from code with the following copyright |
|
|
51 |
|
|
52 |
|
|
53 /* @(#)k_sin.c 1.3 95/01/18 */ |
|
|
54 /* |
|
|
55 * ==================================================== |
|
|
56 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. |
|
|
57 * |
|
|
58 * Developed at SunSoft, a Sun Microsystems, Inc. business. |
|
|
59 * Permission to use, copy, modify, and distribute this |
|
|
60 * software is freely granted, provided that this notice |
|
|
61 * is preserved. |
|
|
62 * ==================================================== |
|
|
63 */ |
|
|
64 |
|
|
65 /* __kernel_sin( x, y, iy) |
|
|
66 * kernel sin function on [-pi/4, pi/4], pi/4 ~ 0.7854 |
|
|
67 * Input x is assumed to be bounded by ~pi/4 in magnitude. |
|
|
68 * Input y is the tail of x. |
|
|
69 * Input iy indicates whether y is 0. (if iy=0, y assume to be 0). |
|
|
70 * |
|
|
71 * Algorithm |
|
|
72 * 1. Since sin(-x) = -sin(x), we need only to consider positive x. |
|
|
73 * 2. if x < 2^-27 (hx<0x3e400000 0), return x with inexact if x!=0. |
|
|
74 * 3. sin(x) is approximated by a polynomial of degree 13 on |
|
|
75 * [0,pi/4] |
|
|
76 * 3 13 |
|
|
77 * sin(x) ~ x + S1*x + ... + S6*x |
|
|
78 * where |
|
|
79 * |
|
|
80 * |sin(x) 2 4 6 8 10 12 | -58 |
|
|
81 * |----- - (1+S1*x +S2*x +S3*x +S4*x +S5*x +S6*x )| <= 2 |
|
|
82 * | x | |
|
|
83 * |
|
|
84 * 4. sin(x+y) = sin(x) + sin'(x')*y |
|
|
85 * ~ sin(x) + (1-x*x/2)*y |
|
|
86 * For better accuracy, let |
|
|
87 * 3 2 2 2 2 |
|
|
88 * r = x *(S2+x *(S3+x *(S4+x *(S5+x *S6)))) |
|
|
89 * then 3 2 |
|
|
90 * sin(x) = x + (S1*x + (x *(r-y/2)+y)) |
|
|
91 */ |
|
|
92 |
|
|
93 #include "mathincl/fdlibm.h" |
|
|
94 |
|
|
95 static const double |
|
|
96 half = 5.00000000000000000000e-01, /* 0x3FE00000, 0x00000000 */ |
|
|
97 S1 = -1.66666666666666324348e-01, /* 0xBFC55555, 0x55555549 */ |
|
|
98 S2 = 8.33333333332248946124e-03, /* 0x3F811111, 0x1110F8A6 */ |
|
|
99 S3 = -1.98412698298579493134e-04, /* 0xBF2A01A0, 0x19C161D5 */ |
|
|
100 S4 = 2.75573137070700676789e-06, /* 0x3EC71DE3, 0x57B1FE7D */ |
|
|
101 S5 = -2.50507602534068634195e-08, /* 0xBE5AE5E6, 0x8A2B9CEB */ |
|
|
102 S6 = 1.58969099521155010221e-10; /* 0x3DE5D93A, 0x5ACFD57C */ |
|
|
103 |
|
|
104 double __kernel_sin(double x, double y, int iy) |
|
|
105 { |
|
|
106 double z,r,v; |
|
|
107 int ix; |
|
|
108 ix = CYG_LIBM_HI(x)&0x7fffffff; /* high word of x */ |
|
|
109 if(ix<0x3e400000) /* |x| < 2**-27 */ |
|
|
110 {if((int)x==0) return x;} /* generate inexact */ |
|
|
111 z = x*x; |
|
|
112 v = z*x; |
|
|
113 r = S2+z*(S3+z*(S4+z*(S5+z*S6))); |
|
|
114 if(iy==0) return x+v*(S1+z*r); |
|
|
115 else return x-((z*(half*y-v*r)-y)-v*S1); |
|
|
116 } |
|
|
117 |
|
|
118 #endif // ifdef CYGPKG_LIBM |
|
|
119 |
|
|
120 // EOF k_sin.c |