POK
/home/jaouen/pok_official/pok/trunk/libpok/libm/e_acosh.c
00001 /*
00002  *                               POK header
00003  * 
00004  * The following file is a part of the POK project. Any modification should
00005  * made according to the POK licence. You CANNOT use this file or a part of
00006  * this file is this part of a file for your own project
00007  *
00008  * For more information on the POK licence, please see our LICENCE FILE
00009  *
00010  * Please follow the coding guidelines described in doc/CODING_GUIDELINES
00011  *
00012  *                                      Copyright (c) 2007-2009 POK team 
00013  *
00014  * Created by julien on Fri Jan 30 14:41:34 2009 
00015  */
00016 
00017 /* @(#)e_acosh.c 5.1 93/09/24 */
00018 /*
00019  * ====================================================
00020  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
00021  *
00022  * Developed at SunPro, a Sun Microsystems, Inc. business.
00023  * Permission to use, copy, modify, and distribute this
00024  * software is freely granted, provided that this notice
00025  * is preserved.
00026  * ====================================================
00027  */
00028 
00029 /* __ieee754_acosh(x)
00030  * Method :
00031  *      Based on
00032  *              acosh(x) = log [ x + sqrt(x*x-1) ]
00033  *      we have
00034  *              acosh(x) := log(x)+ln2, if x is large; else
00035  *              acosh(x) := log(2x-1/(sqrt(x*x-1)+x)) if x>2; else
00036  *              acosh(x) := log1p(t+sqrt(2.0*t+t*t)); where t=x-1.
00037  *
00038  * Special cases:
00039  *      acosh(x) is NaN with signal if x<1.
00040  *      acosh(NaN) is NaN without signal.
00041  */
00042 
00043 #ifdef POK_NEEDS_LIBMATH
00044 
00045 #include <libm.h>
00046 #include "math_private.h"
00047 
00048 static const double
00049 one     = 1.0,
00050 ln2     = 6.93147180559945286227e-01;  /* 0x3FE62E42, 0xFEFA39EF */
00051 
00052 double
00053 __ieee754_acosh(double x)
00054 {
00055         double t;
00056         int32_t hx;
00057         uint32_t lx;
00058         EXTRACT_WORDS(hx,lx,x);
00059         if(hx<0x3ff00000) {             /* x < 1 */
00060             return (x-x)/(x-x);
00061         } else if(hx >=0x41b00000) {    /* x > 2**28 */
00062             if(hx >=0x7ff00000) {       /* x is inf of NaN */
00063                 return x+x;
00064             } else
00065                 return __ieee754_log(x)+ln2;    /* acosh(huge)=log(2x) */
00066         } else if(((hx-0x3ff00000)|lx)==0) {
00067             return 0.0;                 /* acosh(1) = 0 */
00068         } else if (hx > 0x40000000) {   /* 2**28 > x > 2 */
00069             t=x*x;
00070             return __ieee754_log(2.0*x-one/(x+__ieee754_sqrt(t-one)));
00071         } else {                        /* 1<x<2 */
00072             t = x-one;
00073             return log1p(t+sqrt(2.0*t+t*t));
00074         }
00075 }
00076 
00077 #endif