Back to index

glibc  2.9
e_acoshl.c
Go to the documentation of this file.
00001 /* e_acoshl.c -- long double version of e_acosh.c.
00002  * Conversion to long double by Jakub Jelinek, jj@ultra.linux.cz.
00003  */
00004 
00005 /*
00006  * ====================================================
00007  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
00008  *
00009  * Developed at SunPro, a Sun Microsystems, Inc. business.
00010  * Permission to use, copy, modify, and distribute this
00011  * software is freely granted, provided that this notice
00012  * is preserved.
00013  * ====================================================
00014  */
00015 
00016 /* __ieee754_acoshl(x)
00017  * Method :
00018  *     Based on
00019  *            acoshl(x) = logl [ x + sqrtl(x*x-1) ]
00020  *     we have
00021  *            acoshl(x) := logl(x)+ln2,   if x is large; else
00022  *            acoshl(x) := logl(2x-1/(sqrtl(x*x-1)+x)) if x>2; else
00023  *            acoshl(x) := log1pl(t+sqrtl(2.0*t+t*t)); where t=x-1.
00024  *
00025  * Special cases:
00026  *     acoshl(x) is NaN with signal if x<1.
00027  *     acoshl(NaN) is NaN without signal.
00028  */
00029 
00030 #include "math.h"
00031 #include "math_private.h"
00032 
00033 #ifdef __STDC__
00034 static const long double
00035 #else
00036 static long double
00037 #endif
00038 one    = 1.0,
00039 ln2    = 0.6931471805599453094172321214581766L;
00040 
00041 #ifdef __STDC__
00042        long double __ieee754_acoshl(long double x)
00043 #else
00044        long double __ieee754_acoshl(x)
00045        long double x;
00046 #endif
00047 {
00048        long double t;
00049        u_int64_t lx;
00050        int64_t hx;
00051        GET_LDOUBLE_WORDS64(hx,lx,x);
00052        if(hx<0x3fff000000000000LL) {             /* x < 1 */
00053            return (x-x)/(x-x);
00054        } else if(hx >=0x4035000000000000LL) {    /* x > 2**54 */
00055            if(hx >=0x7fff000000000000LL) {       /* x is inf of NaN */
00056                return x+x;
00057            } else
00058               return __ieee754_logl(x)+ln2;      /* acoshl(huge)=logl(2x) */
00059        } else if(((hx-0x3fff000000000000LL)|lx)==0) {
00060            return 0.0L;                   /* acosh(1) = 0 */
00061        } else if (hx > 0x4000000000000000LL) {   /* 2**28 > x > 2 */
00062            t=x*x;
00063            return __ieee754_logl(2.0L*x-one/(x+__ieee754_sqrtl(t-one)));
00064        } else {                    /* 1<x<2 */
00065            t = x-one;
00066            return __log1pl(t+__sqrtl(2.0L*t+t*t));
00067        }
00068 }