sincosq.c revision 1.1 1 1.1 mrg /* Compute sine and cosine of argument.
2 1.1 mrg Copyright (C) 1997-2018 Free Software Foundation, Inc.
3 1.1 mrg This file is part of the GNU C Library.
4 1.1 mrg Contributed by Ulrich Drepper <drepper (at) cygnus.com>, 1997 and
5 1.1 mrg Jakub Jelinek <jj (at) ultra.linux.cz>.
6 1.1 mrg
7 1.1 mrg The GNU C Library is free software; you can redistribute it and/or
8 1.1 mrg modify it under the terms of the GNU Lesser General Public
9 1.1 mrg License as published by the Free Software Foundation; either
10 1.1 mrg version 2.1 of the License, or (at your option) any later version.
11 1.1 mrg
12 1.1 mrg The GNU C Library is distributed in the hope that it will be useful,
13 1.1 mrg but WITHOUT ANY WARRANTY; without even the implied warranty of
14 1.1 mrg MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 1.1 mrg Lesser General Public License for more details.
16 1.1 mrg
17 1.1 mrg You should have received a copy of the GNU Lesser General Public
18 1.1 mrg License along with the GNU C Library; if not, see
19 1.1 mrg <http://www.gnu.org/licenses/>. */
20 1.1 mrg
21 1.1 mrg #include "quadmath-imp.h"
22 1.1 mrg
23 1.1 mrg void
24 1.1 mrg sincosq (__float128 x, __float128 *sinx, __float128 *cosx)
25 1.1 mrg {
26 1.1 mrg int64_t ix;
27 1.1 mrg
28 1.1 mrg /* High word of x. */
29 1.1 mrg GET_FLT128_MSW64 (ix, x);
30 1.1 mrg
31 1.1 mrg /* |x| ~< pi/4 */
32 1.1 mrg ix &= 0x7fffffffffffffffLL;
33 1.1 mrg if (ix <= 0x3ffe921fb54442d1LL)
34 1.1 mrg __quadmath_kernel_sincosq (x, 0, sinx, cosx, 0);
35 1.1 mrg else if (ix >= 0x7fff000000000000LL)
36 1.1 mrg {
37 1.1 mrg /* sin(Inf or NaN) is NaN */
38 1.1 mrg *sinx = *cosx = x - x;
39 1.1 mrg if (isinfq (x))
40 1.1 mrg errno = EDOM;
41 1.1 mrg }
42 1.1 mrg else
43 1.1 mrg {
44 1.1 mrg /* Argument reduction needed. */
45 1.1 mrg __float128 y[2];
46 1.1 mrg int n;
47 1.1 mrg
48 1.1 mrg n = __quadmath_rem_pio2q (x, y);
49 1.1 mrg switch (n & 3)
50 1.1 mrg {
51 1.1 mrg case 0:
52 1.1 mrg __quadmath_kernel_sincosq (y[0], y[1], sinx, cosx, 1);
53 1.1 mrg break;
54 1.1 mrg case 1:
55 1.1 mrg __quadmath_kernel_sincosq (y[0], y[1], cosx, sinx, 1);
56 1.1 mrg *cosx = -*cosx;
57 1.1 mrg break;
58 1.1 mrg case 2:
59 1.1 mrg __quadmath_kernel_sincosq (y[0], y[1], sinx, cosx, 1);
60 1.1 mrg *sinx = -*sinx;
61 1.1 mrg *cosx = -*cosx;
62 1.1 mrg break;
63 1.1 mrg default:
64 1.1 mrg __quadmath_kernel_sincosq (y[0], y[1], cosx, sinx, 1);
65 1.1 mrg *sinx = -*sinx;
66 1.1 mrg break;
67 1.1 mrg }
68 1.1 mrg }
69 1.1 mrg }
70