cosl.c revision ddc0e0b53c661f6e439e3b7072b3ef353eadb4af
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * CDDL HEADER START
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * The contents of this file are subject to the terms of the
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * Common Development and Distribution License (the "License").
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * You may not use this file except in compliance with the License.
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * or http://www.opensolaris.org/os/licensing.
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * See the License for the specific language governing permissions
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * and limitations under the License.
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * When distributing Covered Code, include this CDDL HEADER in each
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * If applicable, add the following below this CDDL HEADER, with the
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * fields enclosed by brackets "[]" replaced with your own identifying
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * information: Portions Copyright [yyyy] [name of copyright owner]
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * CDDL HEADER END
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * Use is subject to license terms.
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis/* INDENT OFF */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * Table look-up algorithm by K.C. Ng, November, 1989.
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * kernel function:
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * __k_sinl ... sin function on [-pi/4,pi/4]
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * __k_cosl ... cos function on [-pi/4,pi/4]
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * __rem_pio2l ... argument reduction routine
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * Let S and C denote the sin and cos respectively on [-PI/4, +PI/4].
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * 1. Assume the argument x is reduced to y1+y2 = x-k*pi/2 in
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * [-pi/2 , +pi/2], and let n = k mod 4.
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * 2. Let S=S(y1+y2), C=C(y1+y2). Depending on n, we have
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * n sin(x) cos(x) tan(x)
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * ----------------------------------------------------------
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * ----------------------------------------------------------
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * Special cases:
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * Let trig be any of sin, cos, or tan.
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * trig(+-INF) is NaN, with signals;
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * trig(NaN) is that NaN;
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis * computer TRIG(x) returns trig(x) nearly rounded.
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis/* INDENT ON */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtiscosl(long double x) {
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis int *px = (int *) &x;
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis /* trig(Inf or NaN) is NaN */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis /* High word of x. */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis /* |x| ~< pi/4 */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis /* argument reduction needed */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis switch (n & 3) {
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis /* NOTREACHED */