2 * Copyright (c) 2017, 2023 Steven G. Kargl
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice unmodified, this list of conditions, and the following
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 * See ../src/s_cospi.c for implementation details.
38 #include "math_private.h"
41 pi_hi = 3.1415926814079285e+00, /* 0x400921fb 0x58000000 */
42 pi_lo =-2.7818135228334233e-08; /* 0xbe5dde97 0x3dcb3b3a */
47 volatile static const double vzero = 0;
57 EXTRACT_LDBL80_WORDS(hx, lx, x);
59 INSERT_LDBL80_WORDS(ax, ix, lx);
63 if (ix < 0x3fff) { /* |x| < 1 */
64 if (ix < 0x3ffd) { /* |x| < 0.25 */
65 if (ix < 0x3fdd) { /* |x| < 0x1p-34 */
69 RETURNI(__kernel_cospil(ax));
72 if (ix < 0x3ffe) /* |x| < 0.5 */
73 c = __kernel_sinpil(0.5 - ax);
74 else if (lx < 0xc000000000000000ull) { /* |x| < 0.75 */
77 c = -__kernel_sinpil(ax - 0.5);
79 c = -__kernel_cospil(1 - ax);
83 if (ix < 0x403e) { /* 1 <= |x| < 0x1p63 */
84 FFLOORL80(x, j0, ix, lx); /* Integer part of ax. */
86 EXTRACT_LDBL80_WORDS(ix, lx, ax);
88 if (ix < 0x3ffe) { /* |x| < 0.5 */
89 if (ix < 0x3ffd) /* |x| < 0.25 */
90 c = ix == 0 ? 1 : __kernel_cospil(ax);
92 c = __kernel_sinpil(0.5 - ax);
95 if (lx < 0xc000000000000000ull) { /* |x| < 0.75 */
98 c = -__kernel_sinpil(ax - 0.5);
100 c = -__kernel_cospil(1 - ax);
109 RETURNI(j0 & 1 ? -c : c);
113 RETURNI(vzero / vzero);
116 * For 0x1p63 <= |x| < 0x1p64 need to determine if x is an even
117 * or odd integer to return t = +1 or -1.
118 * For |x| >= 0x1p64, it is always an even integer, so t = 1.
120 RETURNI(ix >= 0x403f ? 1 : ((lx & 1) ? -1 : 1));