Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.base/share/native/libfdlibm/k_sin.c
41149 views
1
/*
2
* Copyright (c) 1998, 2001, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
10
*
11
* This code is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
* version 2 for more details (a copy is included in the LICENSE file that
15
* accompanied this code).
16
*
17
* You should have received a copy of the GNU General Public License version
18
* 2 along with this work; if not, write to the Free Software Foundation,
19
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20
*
21
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
* or visit www.oracle.com if you need additional information or have any
23
* questions.
24
*/
25
26
/* __kernel_sin( x, y, iy)
27
* kernel sin function on [-pi/4, pi/4], pi/4 ~ 0.7854
28
* Input x is assumed to be bounded by ~pi/4 in magnitude.
29
* Input y is the tail of x.
30
* Input iy indicates whether y is 0. (if iy=0, y assume to be 0).
31
*
32
* Algorithm
33
* 1. Since sin(-x) = -sin(x), we need only to consider positive x.
34
* 2. if x < 2^-27 (hx<0x3e400000 0), return x with inexact if x!=0.
35
* 3. sin(x) is approximated by a polynomial of degree 13 on
36
* [0,pi/4]
37
* 3 13
38
* sin(x) ~ x + S1*x + ... + S6*x
39
* where
40
*
41
* |sin(x) 2 4 6 8 10 12 | -58
42
* |----- - (1+S1*x +S2*x +S3*x +S4*x +S5*x +S6*x )| <= 2
43
* | x |
44
*
45
* 4. sin(x+y) = sin(x) + sin'(x')*y
46
* ~ sin(x) + (1-x*x/2)*y
47
* For better accuracy, let
48
* 3 2 2 2 2
49
* r = x *(S2+x *(S3+x *(S4+x *(S5+x *S6))))
50
* then 3 2
51
* sin(x) = x + (S1*x + (x *(r-y/2)+y))
52
*/
53
54
#include "fdlibm.h"
55
56
#ifdef __STDC__
57
static const double
58
#else
59
static double
60
#endif
61
half = 5.00000000000000000000e-01, /* 0x3FE00000, 0x00000000 */
62
S1 = -1.66666666666666324348e-01, /* 0xBFC55555, 0x55555549 */
63
S2 = 8.33333333332248946124e-03, /* 0x3F811111, 0x1110F8A6 */
64
S3 = -1.98412698298579493134e-04, /* 0xBF2A01A0, 0x19C161D5 */
65
S4 = 2.75573137070700676789e-06, /* 0x3EC71DE3, 0x57B1FE7D */
66
S5 = -2.50507602534068634195e-08, /* 0xBE5AE5E6, 0x8A2B9CEB */
67
S6 = 1.58969099521155010221e-10; /* 0x3DE5D93A, 0x5ACFD57C */
68
69
#ifdef __STDC__
70
double __kernel_sin(double x, double y, int iy)
71
#else
72
double __kernel_sin(x, y, iy)
73
double x,y; int iy; /* iy=0 if y is zero */
74
#endif
75
{
76
double z,r,v;
77
int ix;
78
ix = __HI(x)&0x7fffffff; /* high word of x */
79
if(ix<0x3e400000) /* |x| < 2**-27 */
80
{if((int)x==0) return x;} /* generate inexact */
81
z = x*x;
82
v = z*x;
83
r = S2+z*(S3+z*(S4+z*(S5+z*S6)));
84
if(iy==0) return x+v*(S1+z*r);
85
else return x-((z*(half*y-v*r)-y)-v*S1);
86
}
87
88