1285809Sscottl/*- 2285809Sscottl * Copyright (c) 2008 David Schultz <das@FreeBSD.ORG> 3285809Sscottl * All rights reserved. 4285809Sscottl * 5285809Sscottl * Redistribution and use in source and binary forms, with or without 6285809Sscottl * modification, are permitted provided that the following conditions 7285809Sscottl * are met: 8285809Sscottl * 1. Redistributions of source code must retain the above copyright 9285809Sscottl * notice, this list of conditions and the following disclaimer. 10285809Sscottl * 2. Redistributions in binary form must reproduce the above copyright 11285809Sscottl * notice, this list of conditions and the following disclaimer in the 12285809Sscottl * documentation and/or other materials provided with the distribution. 13285809Sscottl * 14285809Sscottl * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15285809Sscottl * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16285809Sscottl * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17285809Sscottl * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18285809Sscottl * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19285809Sscottl * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20285809Sscottl * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21285809Sscottl * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22285809Sscottl * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23285809Sscottl * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24285809Sscottl * SUCH DAMAGE. 25285809Sscottl * 26285809Sscottl * $FreeBSD: releng/10.3/lib/msun/ld128/invtrig.h 181074 2008-07-31 22:41:26Z das $ 27285809Sscottl */ 28285809Sscottl 29285809Sscottl#include <float.h> 30285809Sscottl 31285809Sscottl#include "fpmath.h" 32285809Sscottl 33285809Sscottl#define BIAS (LDBL_MAX_EXP - 1) 34285809Sscottl#define MANH_SIZE (LDBL_MANH_SIZE + 1) 35285809Sscottl 36285809Sscottl/* Approximation thresholds. */ 37285809Sscottl#define ASIN_LINEAR (BIAS - 56) /* 2**-56 */ 38285809Sscottl#define ACOS_CONST (BIAS - 113) /* 2**-113 */ 39285809Sscottl#define ATAN_CONST (BIAS + 113) /* 2**113 */ 40285809Sscottl#define ATAN_LINEAR (BIAS - 56) /* 2**-56 */ 41285809Sscottl 42285809Sscottl/* 0.95 */ 43285809Sscottl#define THRESH ((0xe666666666666666ULL>>(64-(MANH_SIZE-1)))|LDBL_NBIT) 44285809Sscottl 45285809Sscottl/* Constants shared by the long double inverse trig functions. */ 46285809Sscottl#define pS0 _ItL_pS0 47285809Sscottl#define pS1 _ItL_pS1 48285809Sscottl#define pS2 _ItL_pS2 49285809Sscottl#define pS3 _ItL_pS3 50285809Sscottl#define pS4 _ItL_pS4 51285809Sscottl#define pS5 _ItL_pS5 52285809Sscottl#define pS6 _ItL_pS6 53285809Sscottl#define pS7 _ItL_pS7 54285809Sscottl#define pS8 _ItL_pS8 55285809Sscottl#define pS9 _ItL_pS9 56285809Sscottl#define qS1 _ItL_qS1 57285809Sscottl#define qS2 _ItL_qS2 58285809Sscottl#define qS3 _ItL_qS3 59285809Sscottl#define qS4 _ItL_qS4 60285809Sscottl#define qS5 _ItL_qS5 61285809Sscottl#define qS6 _ItL_qS6 62285809Sscottl#define qS7 _ItL_qS7 63285809Sscottl#define qS8 _ItL_qS8 64285809Sscottl#define qS9 _ItL_qS9 65285809Sscottl#define atanhi _ItL_atanhi 66285809Sscottl#define atanlo _ItL_atanlo 67285809Sscottl#define aT _ItL_aT 68285809Sscottl#define pi_lo _ItL_pi_lo 69285809Sscottl 70285809Sscottl#define pio2_hi atanhi[3] 71285809Sscottl#define pio2_lo atanlo[3] 72285809Sscottl#define pio4_hi atanhi[1] 73285809Sscottl 74285809Sscottl/* Constants shared by the long double inverse trig functions. */ 75285809Sscottlextern const long double pS0, pS1, pS2, pS3, pS4, pS5, pS6, pS7, pS8, pS9; 76285809Sscottlextern const long double qS1, qS2, qS3, qS4, qS5, qS6, qS7, qS8, qS9; 77285809Sscottlextern const long double atanhi[], atanlo[], aT[]; 78285809Sscottlextern const long double pi_lo; 79285809Sscottl 80285809Sscottlstatic inline long double 81285809SscottlP(long double x) 82285809Sscottl{ 83285809Sscottl 84285809Sscottl return (x * (pS0 + x * (pS1 + x * (pS2 + x * (pS3 + x * \ 85285809Sscottl (pS4 + x * (pS5 + x * (pS6 + x * (pS7 + x * (pS8 + x * \ 86285809Sscottl pS9)))))))))); 87285809Sscottl} 88285809Sscottl 89285809Sscottlstatic inline long double 90285809SscottlQ(long double x) 91285809Sscottl{ 92285809Sscottl 93285809Sscottl return (1.0 + x * (qS1 + x * (qS2 + x * (qS3 + x * (qS4 + x * \ 94285809Sscottl (qS5 + x * (qS6 + x * (qS7 + x * (qS8 + x * qS9))))))))); 95285809Sscottl} 96285809Sscottl 97285809Sscottlstatic inline long double 98285809SscottlT_even(long double x) 99285809Sscottl{ 100285809Sscottl 101285809Sscottl return (aT[0] + x * (aT[2] + x * (aT[4] + x * (aT[6] + x * \ 102285809Sscottl (aT[8] + x * (aT[10] + x * (aT[12] + x * (aT[14] + x * \ 103285809Sscottl (aT[16] + x * (aT[18] + x * (aT[20] + x * aT[22]))))))))))); 104285809Sscottl} 105285809Sscottl 106285809Sscottlstatic inline long double 107285809SscottlT_odd(long double x) 108285809Sscottl{ 109285809Sscottl 110285809Sscottl return (aT[1] + x * (aT[3] + x * (aT[5] + x * (aT[7] + x * \ 111285809Sscottl (aT[9] + x * (aT[11] + x * (aT[13] + x * (aT[15] + x * \ 112285809Sscottl (aT[17] + x * (aT[19] + x * (aT[21] + x * aT[23]))))))))))); 113285809Sscottl} 114285809Sscottl