Path: blob/master/src/java.base/share/native/libfdlibm/e_atanh.c
41149 views
/*1* Copyright (c) 1998, 2001, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425/* __ieee754_atanh(x)26* Method :27* 1.Reduced x to positive by atanh(-x) = -atanh(x)28* 2.For x>=0.529* 1 2x x30* atanh(x) = --- * log(1 + -------) = 0.5 * log1p(2 * --------)31* 2 1 - x 1 - x32*33* For x<0.534* atanh(x) = 0.5*log1p(2x+2x*x/(1-x))35*36* Special cases:37* atanh(x) is NaN if |x| > 1 with signal;38* atanh(NaN) is that NaN with no signal;39* atanh(+-1) is +-INF with signal.40*41*/4243#include "fdlibm.h"4445#ifdef __STDC__46static const double one = 1.0, huge = 1e300;47#else48static double one = 1.0, huge = 1e300;49#endif5051static double zero = 0.0;5253#ifdef __STDC__54double __ieee754_atanh(double x)55#else56double __ieee754_atanh(x)57double x;58#endif59{60double t;61int hx,ix;62unsigned lx;63hx = __HI(x); /* high word */64lx = __LO(x); /* low word */65ix = hx&0x7fffffff;66if ((ix|((lx|(-lx))>>31))>0x3ff00000) /* |x|>1 */67return (x-x)/(x-x);68if(ix==0x3ff00000)69return x/zero;70if(ix<0x3e300000&&(huge+x)>zero) return x; /* x<2**-28 */71__HI(x) = ix; /* x <- |x| */72if(ix<0x3fe00000) { /* x < 0.5 */73t = x+x;74t = 0.5*log1p(t+t*x/(one-x));75} else76t = 0.5*log1p((x+x)/(one-x));77if(hx>=0) return t; else return -t;78}798081