Back to index

glibc  2.9
e_atanhl.c
Go to the documentation of this file.
00001 /* @(#)e_atanh.c 5.1 93/09/24 */
00002 /*
00003  * ====================================================
00004  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
00005  *
00006  * Developed at SunPro, a Sun Microsystems, Inc. business.
00007  * Permission to use, copy, modify, and distribute this
00008  * software is freely granted, provided that this notice
00009  * is preserved.
00010  * ====================================================
00011  */
00012 
00013 #if defined(LIBM_SCCS) && !defined(lint)
00014 static char rcsid[] = "$NetBSD: e_atanh.c,v 1.8 1995/05/10 20:44:55 jtc Exp $";
00015 #endif
00016 
00017 /* __ieee754_atanh(x)
00018  * Method :
00019  *    1.Reduced x to positive by atanh(-x) = -atanh(x)
00020  *    2.For x>=0.5
00021  *                  1              2x                          x
00022  *     atanh(x) = --- * log(1 + -------) = 0.5 * log1p(2 * --------)
00023  *                  2             1 - x                      1 - x
00024  *
00025  *     For x<0.5
00026  *     atanh(x) = 0.5*log1p(2x+2x*x/(1-x))
00027  *
00028  * Special cases:
00029  *     atanh(x) is NaN if |x| > 1 with signal;
00030  *     atanh(NaN) is that NaN with no signal;
00031  *     atanh(+-1) is +-INF with signal.
00032  *
00033  */
00034 
00035 #include "math.h"
00036 #include "math_private.h"
00037 
00038 #ifdef __STDC__
00039 static const long double one = 1.0L, huge = 1e300L;
00040 #else
00041 static long double one = 1.0L, huge = 1e300L;
00042 #endif
00043 
00044 #ifdef __STDC__
00045 static const long double zero = 0.0L;
00046 #else
00047 static long double zero = 0.0L;
00048 #endif
00049 
00050 #ifdef __STDC__
00051        long double __ieee754_atanhl(long double x)
00052 #else
00053        long double __ieee754_atanhl(x)
00054        long double x;
00055 #endif
00056 {
00057        long double t;
00058        int64_t hx,ix;
00059        u_int64_t lx;
00060        GET_LDOUBLE_WORDS64(hx,lx,x);
00061        ix = hx&0x7fffffffffffffffLL;
00062        if (ix >= 0x3ff0000000000000LL) { /* |x|>=1 */
00063            if (ix > 0x3ff0000000000000LL)
00064               return (x-x)/(x-x);
00065            t = fabsl (x);
00066            if (t > one)
00067               return (x-x)/(x-x);
00068            if (t == one)
00069               return x/zero;
00070        }
00071        if(ix<0x3e20000000000000LL&&(huge+x)>zero) return x;    /* x<2**-29 */
00072        x = fabsl (x);
00073        if(ix<0x3fe0000000000000LL) {             /* x < 0.5 */
00074            t = x+x;
00075            t = 0.5*__log1pl(t+t*x/(one-x));
00076        } else
00077            t = 0.5*__log1pl((x+x)/(one-x));
00078        if(hx>=0) return t; else return -t;
00079 }