xref: /titanic_41/usr/src/lib/libm/common/Q/sincosl.c (revision a9d3dcd5820128b4f34bf38f447e47aa95c004e8)
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 
305b2ba9d3SPiotr Jasiukajtis /*
315b2ba9d3SPiotr Jasiukajtis  * sincosl(x)
325b2ba9d3SPiotr Jasiukajtis  * Table look-up algorithm by K.C. Ng, November, 1989.
335b2ba9d3SPiotr Jasiukajtis  *
345b2ba9d3SPiotr Jasiukajtis  * kernel function:
355b2ba9d3SPiotr Jasiukajtis  *	__k_sincosl	... sin and cos function on [-pi/4,pi/4]
365b2ba9d3SPiotr Jasiukajtis  *	__rem_pio2l	... argument reduction routine
375b2ba9d3SPiotr Jasiukajtis  *
385b2ba9d3SPiotr Jasiukajtis  * Method.
395b2ba9d3SPiotr Jasiukajtis  *      Let S and C denote the sin and cos respectively on [-PI/4, +PI/4].
405b2ba9d3SPiotr Jasiukajtis  *      1. Assume the argument x is reduced to y1+y2 = x-k*pi/2 in
415b2ba9d3SPiotr Jasiukajtis  *	   [-pi/2 , +pi/2], and let n = k mod 4.
425b2ba9d3SPiotr Jasiukajtis  *	2. Let S=S(y1+y2), C=C(y1+y2). Depending on n, we have
435b2ba9d3SPiotr Jasiukajtis  *
445b2ba9d3SPiotr Jasiukajtis  *          n        sin(x)      cos(x)        tan(x)
455b2ba9d3SPiotr Jasiukajtis  *     ----------------------------------------------------------
465b2ba9d3SPiotr Jasiukajtis  *	    0	       S	   C		 S/C
475b2ba9d3SPiotr Jasiukajtis  *	    1	       C	  -S		-C/S
485b2ba9d3SPiotr Jasiukajtis  *	    2	      -S	  -C		 S/C
495b2ba9d3SPiotr Jasiukajtis  *	    3	      -C	   S		-C/S
505b2ba9d3SPiotr Jasiukajtis  *     ----------------------------------------------------------
515b2ba9d3SPiotr Jasiukajtis  *
525b2ba9d3SPiotr Jasiukajtis  * Special cases:
535b2ba9d3SPiotr Jasiukajtis  *      Let trig be any of sin, cos, or tan.
545b2ba9d3SPiotr Jasiukajtis  *      trig(+-INF)  is NaN, with signals;
555b2ba9d3SPiotr Jasiukajtis  *      trig(NaN)    is that NaN;
565b2ba9d3SPiotr Jasiukajtis  *
575b2ba9d3SPiotr Jasiukajtis  * Accuracy:
585b2ba9d3SPiotr Jasiukajtis  *	computer TRIG(x) returns trig(x) nearly rounded.
595b2ba9d3SPiotr Jasiukajtis  */
605b2ba9d3SPiotr Jasiukajtis 
61*a9d3dcd5SRichard Lowe #pragma weak __sincosl = sincosl
625b2ba9d3SPiotr Jasiukajtis 
635b2ba9d3SPiotr Jasiukajtis #include "libm.h"
645b2ba9d3SPiotr Jasiukajtis #include "longdouble.h"
655b2ba9d3SPiotr Jasiukajtis 
665b2ba9d3SPiotr Jasiukajtis void
sincosl(long double x,long double * s,long double * c)675b2ba9d3SPiotr Jasiukajtis sincosl(long double x, long double *s, long double *c) {
685b2ba9d3SPiotr Jasiukajtis 	long double y[2], z = 0.0L;
695b2ba9d3SPiotr Jasiukajtis 	int n, ix;
705b2ba9d3SPiotr Jasiukajtis 
715b2ba9d3SPiotr Jasiukajtis 	ix = *(int *) &x;	/* High word of x */
725b2ba9d3SPiotr Jasiukajtis 
735b2ba9d3SPiotr Jasiukajtis 	/* |x| ~< pi/4 */
745b2ba9d3SPiotr Jasiukajtis 	ix &= 0x7fffffff;
755b2ba9d3SPiotr Jasiukajtis 	if (ix <= 0x3ffe9220)
765b2ba9d3SPiotr Jasiukajtis 		*s = __k_sincosl(x, z, c);
775b2ba9d3SPiotr Jasiukajtis 	else if (ix >= 0x7fff0000)
785b2ba9d3SPiotr Jasiukajtis 		*s = *c = x - x;	/* trig(Inf or NaN) is NaN */
795b2ba9d3SPiotr Jasiukajtis 	else {			/* argument reduction needed */
805b2ba9d3SPiotr Jasiukajtis 		n = __rem_pio2l(x, y);
815b2ba9d3SPiotr Jasiukajtis 		switch (n & 3) {
825b2ba9d3SPiotr Jasiukajtis 		case 0:
835b2ba9d3SPiotr Jasiukajtis 			*s = __k_sincosl(y[0], y[1], c);
845b2ba9d3SPiotr Jasiukajtis 			break;
855b2ba9d3SPiotr Jasiukajtis 		case 1:
865b2ba9d3SPiotr Jasiukajtis 			*c = -__k_sincosl(y[0], y[1], s);
875b2ba9d3SPiotr Jasiukajtis 			break;
885b2ba9d3SPiotr Jasiukajtis 		case 2:
895b2ba9d3SPiotr Jasiukajtis 			*s = -__k_sincosl(y[0], y[1], c);
905b2ba9d3SPiotr Jasiukajtis 			*c = -*c;
915b2ba9d3SPiotr Jasiukajtis 			break;
925b2ba9d3SPiotr Jasiukajtis 		case 3:
935b2ba9d3SPiotr Jasiukajtis 			*c = __k_sincosl(y[0], y[1], s);
945b2ba9d3SPiotr Jasiukajtis 			*s = -*s;
955b2ba9d3SPiotr Jasiukajtis 			break;
965b2ba9d3SPiotr Jasiukajtis 		}
975b2ba9d3SPiotr Jasiukajtis 	}
985b2ba9d3SPiotr Jasiukajtis }
99