1176357Sdas/* From: @(#)k_sin.c 1.3 95/01/18 */
2176357Sdas/*
3176357Sdas * ====================================================
4176357Sdas * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
5176357Sdas * Copyright (c) 2008 Steven G. Kargl, David Schultz, Bruce D. Evans.
6176357Sdas *
7176357Sdas * Developed at SunSoft, a Sun Microsystems, Inc. business.
8176357Sdas * Permission to use, copy, modify, and distribute this
9176357Sdas * software is freely granted, provided that this notice
10176357Sdas * is preserved.
11176357Sdas * ====================================================
12176357Sdas */
13176357Sdas
14176357Sdas#include <sys/cdefs.h>
15176357Sdas__FBSDID("$FreeBSD$");
16176357Sdas
17176357Sdas/*
18176357Sdas * ld80 version of k_sin.c.  See ../src/k_sin.c for most comments.
19176357Sdas */
20176357Sdas
21176357Sdas#include "math_private.h"
22176357Sdas
23176357Sdasstatic const double
24176357Sdashalf =  0.5;
25176357Sdas
26176357Sdas/*
27176357Sdas * Domain [-0.7854, 0.7854], range ~[-1.89e-22, 1.915e-22]
28176357Sdas * |sin(x)/x - s(x)| < 2**-72.1
29176357Sdas *
30176357Sdas * See ../ld80/k_cosl.c for more details about the polynomial.
31176357Sdas */
32176357Sdas#if defined(__amd64__) || defined(__i386__)
33176357Sdas/* Long double constants are slow on these arches, and broken on i386. */
34176357Sdasstatic const volatile double
35176357SdasS1hi = -0.16666666666666666,		/* -0x15555555555555.0p-55 */
36176357SdasS1lo = -9.2563760475949941e-18;		/* -0x15580000000000.0p-109 */
37176357Sdas#define	S1	((long double)S1hi + S1lo)
38176357Sdas#else
39176357Sdasstatic const long double
40176357SdasS1 = -0.166666666666666666671L;		/* -0xaaaaaaaaaaaaaaab.0p-66 */
41176357Sdas#endif
42176357Sdas
43176357Sdasstatic const double
44176357SdasS2 =  0.0083333333333333332,		/*  0x11111111111111.0p-59 */
45176357SdasS3 = -0.00019841269841269427,		/* -0x1a01a01a019f81.0p-65 */
46176357SdasS4 =  0.0000027557319223597490,		/*  0x171de3a55560f7.0p-71 */
47176357SdasS5 = -0.000000025052108218074604,	/* -0x1ae64564f16cad.0p-78 */
48176357SdasS6 =  1.6059006598854211e-10,		/*  0x161242b90243b5.0p-85 */
49176357SdasS7 = -7.6429779983024564e-13,		/* -0x1ae42ebd1b2e00.0p-93 */
50176357SdasS8 =  2.6174587166648325e-15;		/*  0x179372ea0b3f64.0p-101 */
51176357Sdas
52176357Sdaslong double
53176357Sdas__kernel_sinl(long double x, long double y, int iy)
54176357Sdas{
55176357Sdas	long double z,r,v;
56176357Sdas
57176357Sdas	z	=  x*x;
58176357Sdas	v	=  z*x;
59176357Sdas	r	=  S2+z*(S3+z*(S4+z*(S5+z*(S6+z*(S7+z*S8)))));
60176357Sdas	if(iy==0) return x+v*(S1+z*r);
61176357Sdas	else      return x-((z*(half*y-v*r)-y)-v*S1);
62176357Sdas}
63