jdk/src/share/native/java/lang/fdlibm/src/e_acosh.c
changeset 10313 0def93fb66ba
parent 10312 4df16d1321e9
parent 10205 de9223c94f9c
child 10314 9a5858f8a52f
child 10406 70c2151d530b
equal deleted inserted replaced
10312:4df16d1321e9 10313:0def93fb66ba
     1 
       
     2 /*
       
     3  * Copyright (c) 1998, 2001, Oracle and/or its affiliates. All rights reserved.
       
     4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     5  *
       
     6  * This code is free software; you can redistribute it and/or modify it
       
     7  * under the terms of the GNU General Public License version 2 only, as
       
     8  * published by the Free Software Foundation.  Oracle designates this
       
     9  * particular file as subject to the "Classpath" exception as provided
       
    10  * by Oracle in the LICENSE file that accompanied this code.
       
    11  *
       
    12  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    14  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    15  * version 2 for more details (a copy is included in the LICENSE file that
       
    16  * accompanied this code).
       
    17  *
       
    18  * You should have received a copy of the GNU General Public License version
       
    19  * 2 along with this work; if not, write to the Free Software Foundation,
       
    20  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    21  *
       
    22  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    23  * or visit www.oracle.com if you need additional information or have any
       
    24  * questions.
       
    25  */
       
    26 
       
    27 /* __ieee754_acosh(x)
       
    28  * Method :
       
    29  *      Based on
       
    30  *              acosh(x) = log [ x + sqrt(x*x-1) ]
       
    31  *      we have
       
    32  *              acosh(x) := log(x)+ln2, if x is large; else
       
    33  *              acosh(x) := log(2x-1/(sqrt(x*x-1)+x)) if x>2; else
       
    34  *              acosh(x) := log1p(t+sqrt(2.0*t+t*t)); where t=x-1.
       
    35  *
       
    36  * Special cases:
       
    37  *      acosh(x) is NaN with signal if x<1.
       
    38  *      acosh(NaN) is NaN without signal.
       
    39  */
       
    40 
       
    41 #include "fdlibm.h"
       
    42 
       
    43 #ifdef __STDC__
       
    44 static const double
       
    45 #else
       
    46 static double
       
    47 #endif
       
    48 one     = 1.0,
       
    49 ln2     = 6.93147180559945286227e-01;  /* 0x3FE62E42, 0xFEFA39EF */
       
    50 
       
    51 #ifdef __STDC__
       
    52         double __ieee754_acosh(double x)
       
    53 #else
       
    54         double __ieee754_acosh(x)
       
    55         double x;
       
    56 #endif
       
    57 {
       
    58         double t;
       
    59         int hx;
       
    60         hx = __HI(x);
       
    61         if(hx<0x3ff00000) {             /* x < 1 */
       
    62             return (x-x)/(x-x);
       
    63         } else if(hx >=0x41b00000) {    /* x > 2**28 */
       
    64             if(hx >=0x7ff00000) {       /* x is inf of NaN */
       
    65                 return x+x;
       
    66             } else
       
    67                 return __ieee754_log(x)+ln2;    /* acosh(huge)=log(2x) */
       
    68         } else if(((hx-0x3ff00000)|__LO(x))==0) {
       
    69             return 0.0;                 /* acosh(1) = 0 */
       
    70         } else if (hx > 0x40000000) {   /* 2**28 > x > 2 */
       
    71             t=x*x;
       
    72             return __ieee754_log(2.0*x-one/(x+sqrt(t-one)));
       
    73         } else {                        /* 1<x<2 */
       
    74             t = x-one;
       
    75             return log1p(t+sqrt(2.0*t+t*t));
       
    76         }
       
    77 }