15b2ba9d3SPiotr Jasiukajtis /*
25b2ba9d3SPiotr Jasiukajtis * CDDL HEADER START
35b2ba9d3SPiotr Jasiukajtis *
45b2ba9d3SPiotr Jasiukajtis * The contents of this file are subject to the terms of the
55b2ba9d3SPiotr Jasiukajtis * Common Development and Distribution License (the "License").
65b2ba9d3SPiotr Jasiukajtis * You may not use this file except in compliance with the License.
75b2ba9d3SPiotr Jasiukajtis *
85b2ba9d3SPiotr Jasiukajtis * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
95b2ba9d3SPiotr Jasiukajtis * or http://www.opensolaris.org/os/licensing.
105b2ba9d3SPiotr Jasiukajtis * See the License for the specific language governing permissions
115b2ba9d3SPiotr Jasiukajtis * and limitations under the License.
125b2ba9d3SPiotr Jasiukajtis *
135b2ba9d3SPiotr Jasiukajtis * When distributing Covered Code, include this CDDL HEADER in each
145b2ba9d3SPiotr Jasiukajtis * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
155b2ba9d3SPiotr Jasiukajtis * If applicable, add the following below this CDDL HEADER, with the
165b2ba9d3SPiotr Jasiukajtis * fields enclosed by brackets "[]" replaced with your own identifying
175b2ba9d3SPiotr Jasiukajtis * information: Portions Copyright [yyyy] [name of copyright owner]
185b2ba9d3SPiotr Jasiukajtis *
195b2ba9d3SPiotr Jasiukajtis * CDDL HEADER END
205b2ba9d3SPiotr Jasiukajtis */
215b2ba9d3SPiotr Jasiukajtis
225b2ba9d3SPiotr Jasiukajtis /*
235b2ba9d3SPiotr Jasiukajtis * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
245b2ba9d3SPiotr Jasiukajtis */
255b2ba9d3SPiotr Jasiukajtis /*
265b2ba9d3SPiotr Jasiukajtis * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
275b2ba9d3SPiotr Jasiukajtis * Use is subject to license terms.
285b2ba9d3SPiotr Jasiukajtis */
295b2ba9d3SPiotr Jasiukajtis
30*a9d3dcd5SRichard Lowe #pragma weak __sincosl = sincosl
315b2ba9d3SPiotr Jasiukajtis
325b2ba9d3SPiotr Jasiukajtis /* INDENT OFF */
335b2ba9d3SPiotr Jasiukajtis /* cosl(x)
345b2ba9d3SPiotr Jasiukajtis * Table look-up algorithm by K.C. Ng, November, 1989.
355b2ba9d3SPiotr Jasiukajtis *
365b2ba9d3SPiotr Jasiukajtis * kernel function:
375b2ba9d3SPiotr Jasiukajtis * __k_sincosl ... sin and cos function on [-pi/4,pi/4]
385b2ba9d3SPiotr Jasiukajtis * __rem_pio2l ... argument reduction routine
395b2ba9d3SPiotr Jasiukajtis *
405b2ba9d3SPiotr Jasiukajtis * Method.
415b2ba9d3SPiotr Jasiukajtis * Let S and C denote the sin and cos respectively on [-PI/4, +PI/4].
425b2ba9d3SPiotr Jasiukajtis * 1. Assume the argument x is reduced to y1+y2 = x-k*pi/2 in
435b2ba9d3SPiotr Jasiukajtis * [-pi/2 , +pi/2], and let n = k mod 4.
445b2ba9d3SPiotr Jasiukajtis * 2. Let S=S(y1+y2), C=C(y1+y2). Depending on n, we have
455b2ba9d3SPiotr Jasiukajtis *
465b2ba9d3SPiotr Jasiukajtis * n sin(x) cos(x) tan(x)
475b2ba9d3SPiotr Jasiukajtis * ----------------------------------------------------------
485b2ba9d3SPiotr Jasiukajtis * 0 S C S/C
495b2ba9d3SPiotr Jasiukajtis * 1 C -S -C/S
505b2ba9d3SPiotr Jasiukajtis * 2 -S -C S/C
515b2ba9d3SPiotr Jasiukajtis * 3 -C S -C/S
525b2ba9d3SPiotr Jasiukajtis * ----------------------------------------------------------
535b2ba9d3SPiotr Jasiukajtis *
545b2ba9d3SPiotr Jasiukajtis * Special cases:
555b2ba9d3SPiotr Jasiukajtis * Let trig be any of sin, cos, or tan.
565b2ba9d3SPiotr Jasiukajtis * trig(+-INF) is NaN, with signals;
575b2ba9d3SPiotr Jasiukajtis * trig(NaN) is that NaN;
585b2ba9d3SPiotr Jasiukajtis *
595b2ba9d3SPiotr Jasiukajtis * Accuracy:
605b2ba9d3SPiotr Jasiukajtis * computer TRIG(x) returns trig(x) nearly rounded.
615b2ba9d3SPiotr Jasiukajtis */
625b2ba9d3SPiotr Jasiukajtis /* INDENT ON */
635b2ba9d3SPiotr Jasiukajtis
645b2ba9d3SPiotr Jasiukajtis #include "libm.h"
655b2ba9d3SPiotr Jasiukajtis #include "longdouble.h"
665b2ba9d3SPiotr Jasiukajtis
675b2ba9d3SPiotr Jasiukajtis #include <sys/isa_defs.h>
685b2ba9d3SPiotr Jasiukajtis
695b2ba9d3SPiotr Jasiukajtis void
sincosl(long double x,long double * s,long double * c)705b2ba9d3SPiotr Jasiukajtis sincosl(long double x, long double *s, long double *c) {
715b2ba9d3SPiotr Jasiukajtis long double y[2], z = 0.0L;
725b2ba9d3SPiotr Jasiukajtis int n, ix;
735b2ba9d3SPiotr Jasiukajtis #if defined(__i386) || defined(__amd64)
745b2ba9d3SPiotr Jasiukajtis int *px = (int *) &x;
755b2ba9d3SPiotr Jasiukajtis #endif
765b2ba9d3SPiotr Jasiukajtis
775b2ba9d3SPiotr Jasiukajtis /* trig(Inf or NaN) is NaN */
785b2ba9d3SPiotr Jasiukajtis if (!finitel(x)) {
795b2ba9d3SPiotr Jasiukajtis *s = *c = x - x;
805b2ba9d3SPiotr Jasiukajtis return;
815b2ba9d3SPiotr Jasiukajtis }
825b2ba9d3SPiotr Jasiukajtis
835b2ba9d3SPiotr Jasiukajtis /* High word of x. */
845b2ba9d3SPiotr Jasiukajtis #if defined(__i386) || defined(__amd64)
855b2ba9d3SPiotr Jasiukajtis XTOI(px, ix);
865b2ba9d3SPiotr Jasiukajtis #else
875b2ba9d3SPiotr Jasiukajtis ix = *(int *) &x;
885b2ba9d3SPiotr Jasiukajtis #endif
895b2ba9d3SPiotr Jasiukajtis
905b2ba9d3SPiotr Jasiukajtis /* |x| ~< pi/4 */
915b2ba9d3SPiotr Jasiukajtis ix &= 0x7fffffff;
925b2ba9d3SPiotr Jasiukajtis if (ix <= 0x3ffe9220)
935b2ba9d3SPiotr Jasiukajtis *s = __k_sincosl(x, z, c);
945b2ba9d3SPiotr Jasiukajtis
955b2ba9d3SPiotr Jasiukajtis /* argument reduction needed */
965b2ba9d3SPiotr Jasiukajtis else {
975b2ba9d3SPiotr Jasiukajtis n = __rem_pio2l(x, y);
985b2ba9d3SPiotr Jasiukajtis switch (n & 3) {
995b2ba9d3SPiotr Jasiukajtis case 0:
1005b2ba9d3SPiotr Jasiukajtis *s = __k_sincosl(y[0], y[1], c);
1015b2ba9d3SPiotr Jasiukajtis break;
1025b2ba9d3SPiotr Jasiukajtis case 1:
1035b2ba9d3SPiotr Jasiukajtis *c = -__k_sincosl(y[0], y[1], s);
1045b2ba9d3SPiotr Jasiukajtis break;
1055b2ba9d3SPiotr Jasiukajtis case 2:
1065b2ba9d3SPiotr Jasiukajtis *s = -__k_sincosl(y[0], y[1], c);
1075b2ba9d3SPiotr Jasiukajtis *c = -*c;
1085b2ba9d3SPiotr Jasiukajtis break;
1095b2ba9d3SPiotr Jasiukajtis case 3:
1105b2ba9d3SPiotr Jasiukajtis *c = __k_sincosl(y[0], y[1], s);
1115b2ba9d3SPiotr Jasiukajtis *s = -*s;
1125b2ba9d3SPiotr Jasiukajtis }
1135b2ba9d3SPiotr Jasiukajtis }
1145b2ba9d3SPiotr Jasiukajtis }
115