2 * Copyright (c) 2017 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 /* Determine integer part of ax. */
87 lx = (lx >> 32) << 32;
88 lx &= ~(((lx << 32)-1) >> j0);
90 m = (uint64_t)-1 >> (j0 + 1);
93 INSERT_LDBL80_WORDS(x, ix, lx);
96 EXTRACT_LDBL80_WORDS(ix, lx, ax);
98 if (ix < 0x3ffe) { /* |x| < 0.5 */
99 if (ix < 0x3ffd) /* |x| < 0.25 */
100 c = ix == 0 ? 1 : __kernel_cospil(ax);
102 c = __kernel_sinpil(0.5 - ax);
105 if (lx < 0xc000000000000000ull) { /* |x| < 0.75 */
108 c = -__kernel_sinpil(ax - 0.5);
110 c = -__kernel_cospil(1 - ax);
119 RETURNI(j0 & 1 ? -c : c);
123 RETURNI(vzero / vzero);
126 * |x| >= 0x1p63 is always an even integer, so return 1.