Back to index

glibc  2.9
e_acoshl.c
Go to the documentation of this file.
00001 /* @(#)e_acosh.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_acosh.c,v 1.9 1995/05/12 04:57:18 jtc Exp $";
00015 #endif
00016 
00017 /* __ieee754_acosh(x)
00018  * Method :
00019  *     Based on
00020  *            acosh(x) = log [ x + sqrt(x*x-1) ]
00021  *     we have
00022  *            acosh(x) := log(x)+ln2,     if x is large; else
00023  *            acosh(x) := log(2x-1/(sqrt(x*x-1)+x)) if x>2; else
00024  *            acosh(x) := log1p(t+sqrt(2.0*t+t*t)); where t=x-1.
00025  *
00026  * Special cases:
00027  *     acosh(x) is NaN with signal if x<1.
00028  *     acosh(NaN) is NaN without signal.
00029  */
00030 
00031 #include "math.h"
00032 #include "math_private.h"
00033 
00034 #ifdef __STDC__
00035 static const long double
00036 #else
00037 static long double
00038 #endif
00039 one    = 1.0L,
00040 ln2    = 6.93147180559945286227e-01L;  /* 0x3FE62E42, 0xFEFA39EF */
00041 
00042 #ifdef __STDC__
00043        long double __ieee754_acoshl(long double x)
00044 #else
00045        long double __ieee754_acoshl(x)
00046        long double x;
00047 #endif
00048 {
00049        long double t;
00050        int64_t hx;
00051        u_int64_t lx;
00052        GET_LDOUBLE_WORDS64(hx,lx,x);
00053        if(hx<0x3ff0000000000000LL) {             /* x < 1 */
00054            return (x-x)/(x-x);
00055        } else if(hx >=0x41b0000000000000LL) {    /* x > 2**28 */
00056            if(hx >=0x7ff0000000000000LL) {       /* x is inf of NaN */
00057                return x+x;
00058            } else
00059               return __ieee754_logl(x)+ln2;      /* acosh(huge)=log(2x) */
00060        } else if (((hx-0x3ff0000000000000LL)|(lx&0x7fffffffffffffffLL))==0) {
00061            return 0.0;                    /* acosh(1) = 0 */
00062        } else if (hx > 0x4000000000000000LL) {   /* 2**28 > x > 2 */
00063            t=x*x;
00064            return __ieee754_logl(2.0*x-one/(x+__ieee754_sqrtl(t-one)));
00065        } else {                    /* 1<x<2 */
00066            t = x-one;
00067            return __log1p(t+__sqrtl(2.0*t+t*t));
00068        }
00069 }