pty: Activate the signature wrapper of forkpty.
[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 /* Code based on glibc/sysdeps/ieee754/ldbl-128/s_sinl.c.  */
32
33 /* sinl(x)
34  * Return sine function of x.
35  *
36  * kernel function:
37  *      __kernel_sinl           ... sine function on [-pi/4,pi/4]
38  *      __kernel_cosl           ... cosine function on [-pi/4,pi/4]
39  *      __ieee754_rem_pio2l     ... argument reduction routine
40  *
41  * Method.
42  *      Let S,C and T denote the sin, cos and tan respectively on
43  *      [-PI/4, +PI/4]. Reduce the argument x to y1+y2 = x-k*pi/2
44  *      in [-pi/4 , +pi/4], and let n = k mod 4.
45  *      We have
46  *
47  *          n        sin(x)      cos(x)        tan(x)
48  *     ----------------------------------------------------------
49  *          0          S           C             T
50  *          1          C          -S            -1/T
51  *          2         -S          -C             T
52  *          3         -C           S            -1/T
53  *     ----------------------------------------------------------
54  *
55  * Special cases:
56  *      Let trig be any of sin, cos, or tan.
57  *      trig(+-INF)  is NaN, with signals;
58  *      trig(NaN)    is that NaN;
59  *
60  * Accuracy:
61  *      TRIG(x) returns trig(x) nearly rounded
62  */
63
64 # include "trigl.h"
65
66 long double
67 sinl (long double x)
68 {
69   long double y[2], z = 0.0L;
70   int n;
71
72   /* sinl(NaN) is NaN */
73   if (isnanl (x))
74     return x;
75
76   /* |x| ~< pi/4 */
77   if (x >= -0.7853981633974483096156608458198757210492
78       && x <= 0.7853981633974483096156608458198757210492)
79     return kernel_sinl (x, z, 0);
80
81     /* sinl(Inf) is NaN, sinl(0) is 0 */
82   else if (x + x == x)
83     return x - x;               /* NaN */
84
85   /* argument reduction needed */
86   else
87     {
88       n = ieee754_rem_pio2l (x, y);
89       switch (n & 3)
90         {
91         case 0:
92           return kernel_sinl (y[0], y[1], 1);
93         case 1:
94           return kernel_cosl (y[0], y[1]);
95         case 2:
96           return -kernel_sinl (y[0], y[1], 1);
97         default:
98           return -kernel_cosl (y[0], y[1]);
99         }
100     }
101 }
102
103 #endif
104
105 #if 0
106 int
107 main (void)
108 {
109   printf ("%.16Lg\n", sinl (0.7853981633974483096156608458198757210492));
110   printf ("%.16Lg\n", sinl (0.7853981633974483096156608458198757210492 *29));
111   printf ("%.16Lg\n", sinl (0.7853981633974483096156608458198757210492 *2));
112   printf ("%.16Lg\n", sinl (0.7853981633974483096156608458198757210492 *30));
113   printf ("%.16Lg\n", sinl (0.7853981633974483096156608458198757210492 *4));
114   printf ("%.16Lg\n", sinl (0.7853981633974483096156608458198757210492 *32));
115   printf ("%.16Lg\n", sinl (0.7853981633974483096156608458198757210492 *2/3));
116   printf ("%.16Lg\n", sinl (0.7853981633974483096156608458198757210492 *4/3));
117 }
118 #endif