finalise NEWS.stable
[gnulib.git] / lib / sinl.c
1 /* s_sinl.c -- long double version of s_sin.c.
2  * Conversion to long double by Jakub Jelinek, jj@ultra.linux.cz.
3  */
4
5 /*
6  * ====================================================
7  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
8  *
9  * Developed at SunPro, a Sun Microsystems, Inc. business.
10  * Permission to use, copy, modify, and distribute this
11  * software is freely granted, provided that this notice
12  * is preserved.
13  * ====================================================
14  */
15
16 #include <config.h>
17
18 /* Specification.  */
19 #include <math.h>
20
21 #if HAVE_SAME_LONG_DOUBLE_AS_DOUBLE
22
23 long double
24 sinl (long double x)
25 {
26   return sin (x);
27 }
28
29 #else
30
31 /* sinl(x)
32  * Return sine function of x.
33  *
34  * kernel function:
35  *      __kernel_sinl           ... sine function on [-pi/4,pi/4]
36  *      __kernel_cosl           ... cose function on [-pi/4,pi/4]
37  *      __ieee754_rem_pio2l     ... argument reduction routine
38  *
39  * Method.
40  *      Let S,C and T denote the sin, cos and tan respectively on
41  *      [-PI/4, +PI/4]. Reduce the argument x to y1+y2 = x-k*pi/2
42  *      in [-pi/4 , +pi/4], and let n = k mod 4.
43  *      We have
44  *
45  *          n        sin(x)      cos(x)        tan(x)
46  *     ----------------------------------------------------------
47  *          0          S           C             T
48  *          1          C          -S            -1/T
49  *          2         -S          -C             T
50  *          3         -C           S            -1/T
51  *     ----------------------------------------------------------
52  *
53  * Special cases:
54  *      Let trig be any of sin, cos, or tan.
55  *      trig(+-INF)  is NaN, with signals;
56  *      trig(NaN)    is that NaN;
57  *
58  * Accuracy:
59  *      TRIG(x) returns trig(x) nearly rounded
60  */
61
62 # include "trigl.h"
63
64 long double
65 sinl (long double x)
66 {
67   long double y[2], z = 0.0L;
68   int n;
69
70   /* sinl(NaN) is NaN */
71   if (isnanl (x))
72     return x;
73
74   /* |x| ~< pi/4 */
75   if (x >= -0.7853981633974483096156608458198757210492
76       && x <= 0.7853981633974483096156608458198757210492)
77     return kernel_sinl (x, z, 0);
78
79     /* sinl(Inf) is NaN, sinl(0) is 0 */
80   else if (x + x == x)
81     return x - x;               /* NaN */
82
83   /* argument reduction needed */
84   else
85     {
86       n = ieee754_rem_pio2l (x, y);
87       switch (n & 3)
88         {
89         case 0:
90           return kernel_sinl (y[0], y[1], 1);
91         case 1:
92           return kernel_cosl (y[0], y[1]);
93         case 2:
94           return -kernel_sinl (y[0], y[1], 1);
95         default:
96           return -kernel_cosl (y[0], y[1]);
97         }
98     }
99 }
100
101 #endif
102
103 #if 0
104 int
105 main (void)
106 {
107   printf ("%.16Lg\n", sinl (0.7853981633974483096156608458198757210492));
108   printf ("%.16Lg\n", sinl (0.7853981633974483096156608458198757210492 *29));
109   printf ("%.16Lg\n", sinl (0.7853981633974483096156608458198757210492 *2));
110   printf ("%.16Lg\n", sinl (0.7853981633974483096156608458198757210492 *30));
111   printf ("%.16Lg\n", sinl (0.7853981633974483096156608458198757210492 *4));
112   printf ("%.16Lg\n", sinl (0.7853981633974483096156608458198757210492 *32));
113   printf ("%.16Lg\n", sinl (0.7853981633974483096156608458198757210492 *2/3));
114   printf ("%.16Lg\n", sinl (0.7853981633974483096156608458198757210492 *4/3));
115 }
116 #endif