jdk/src/java.base/share/native/libfdlibm/e_asin.c
author avstepan
Thu, 28 Apr 2016 19:35:09 +0300
changeset 38386 d7e7d592d396
parent 25859 3317bb8137f4
child 39759 427916042881
permissions -rw-r--r--
8155021: [TEST] create one more inheritance test for @BeanProperty Reviewed-by: serb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     3
 * Copyright (c) 1998, 2001, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     8
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    10
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    24
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
/* __ieee754_asin(x)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * Method :
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 *      Since  asin(x) = x + x^3/6 + x^5*3/40 + x^7*15/336 + ...
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 *      we approximate asin(x) on [0,0.5] by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 *              asin(x) = x + x*x^2*R(x^2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 *      where
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 *              R(x^2) is a rational approximation of (asin(x)-x)/x^3
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 *      and its remez error is bounded by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 *              |(asin(x)-x)/x^3 - R(x^2)| < 2^(-58.75)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 *      For x in [0.5,1]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 *              asin(x) = pi/2-2*asin(sqrt((1-x)/2))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 *      Let y = (1-x), z = y/2, s := sqrt(z), and pio2_hi+pio2_lo=pi/2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *      then for x>0.98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 *              asin(x) = pi/2 - 2*(s+s*z*R(z))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *                      = pio2_hi - (2*(s+s*z*R(z)) - pio2_lo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *      For x<=0.98, let pio4_hi = pio2_hi/2, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *              f = hi part of s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *              c = sqrt(z) - f = (z-f*f)/(s+f)         ...f+c=sqrt(z)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *      and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *              asin(x) = pi/2 - 2*(s+s*z*R(z))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *                      = pio4_hi+(pio4-2s)-(2s*z*R(z)-pio2_lo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *                      = pio4_hi+(pio4-2f)-(2s*z*R(z)-(pio2_lo+2c))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * Special cases:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *      if x is NaN, return x itself;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *      if |x|>1, return NaN with invalid signal.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
#include "fdlibm.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
#ifdef __STDC__
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
static const double
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
static double
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
one =  1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
huge =  1.000e+300,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
pio2_hi =  1.57079632679489655800e+00, /* 0x3FF921FB, 0x54442D18 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
pio2_lo =  6.12323399573676603587e-17, /* 0x3C91A626, 0x33145C07 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
pio4_hi =  7.85398163397448278999e-01, /* 0x3FE921FB, 0x54442D18 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        /* coefficient for R(x^2) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
pS0 =  1.66666666666666657415e-01, /* 0x3FC55555, 0x55555555 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
pS1 = -3.25565818622400915405e-01, /* 0xBFD4D612, 0x03EB6F7D */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
pS2 =  2.01212532134862925881e-01, /* 0x3FC9C155, 0x0E884455 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
pS3 = -4.00555345006794114027e-02, /* 0xBFA48228, 0xB5688F3B */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
pS4 =  7.91534994289814532176e-04, /* 0x3F49EFE0, 0x7501B288 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
pS5 =  3.47933107596021167570e-05, /* 0x3F023DE1, 0x0DFDF709 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
qS1 = -2.40339491173441421878e+00, /* 0xC0033A27, 0x1C8A2D4B */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
qS2 =  2.02094576023350569471e+00, /* 0x40002AE5, 0x9C598AC8 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
qS3 = -6.88283971605453293030e-01, /* 0xBFE6066C, 0x1B8D0159 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
qS4 =  7.70381505559019352791e-02; /* 0x3FB3B8C5, 0xB12E9282 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
#ifdef __STDC__
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        double __ieee754_asin(double x)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        double __ieee754_asin(x)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        double x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        double t=0,w,p,q,c,r,s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        int hx,ix;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        hx = __HI(x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        ix = hx&0x7fffffff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        if(ix>= 0x3ff00000) {           /* |x|>= 1 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            if(((ix-0x3ff00000)|__LO(x))==0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                    /* asin(1)=+-pi/2 with inexact */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                return x*pio2_hi+x*pio2_lo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            return (x-x)/(x-x);         /* asin(|x|>1) is NaN */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        } else if (ix<0x3fe00000) {     /* |x|<0.5 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            if(ix<0x3e400000) {         /* if |x| < 2**-27 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                if(huge+x>one) return x;/* return x with inexact if x!=0*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            } else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                t = x*x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                p = t*(pS0+t*(pS1+t*(pS2+t*(pS3+t*(pS4+t*pS5)))));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
                q = one+t*(qS1+t*(qS2+t*(qS3+t*qS4)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                w = p/q;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                return x+x*w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        /* 1> |x|>= 0.5 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        w = one-fabs(x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        t = w*0.5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        p = t*(pS0+t*(pS1+t*(pS2+t*(pS3+t*(pS4+t*pS5)))));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        q = one+t*(qS1+t*(qS2+t*(qS3+t*qS4)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        s = sqrt(t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        if(ix>=0x3FEF3333) {    /* if |x| > 0.975 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            w = p/q;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            t = pio2_hi-(2.0*(s+s*w)-pio2_lo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            w  = s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            __LO(w) = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            c  = (t-w*w)/(s+w);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            r  = p/q;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            p  = 2.0*s*r-(pio2_lo-2.0*c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            q  = pio4_hi-2.0*w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            t  = pio4_hi-(p-q);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        if(hx>0) return t; else return -t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
}