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