POK
e_acosh.c
1 /*
2  * POK header
3  *
4  * The following file is a part of the POK project. Any modification should
5  * made according to the POK licence. You CANNOT use this file or a part of
6  * this file is this part of a file for your own project
7  *
8  * For more information on the POK licence, please see our LICENCE FILE
9  *
10  * Please follow the coding guidelines described in doc/CODING_GUIDELINES
11  *
12  * Copyright (c) 2007-2009 POK team
13  *
14  * Created by julien on Fri Jan 30 14:41:34 2009
15  */
16 
17 /* @(#)e_acosh.c 5.1 93/09/24 */
18 /*
19  * ====================================================
20  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
21  *
22  * Developed at SunPro, a Sun Microsystems, Inc. business.
23  * Permission to use, copy, modify, and distribute this
24  * software is freely granted, provided that this notice
25  * is preserved.
26  * ====================================================
27  */
28 
29 /* __ieee754_acosh(x)
30  * Method :
31  * Based on
32  * acosh(x) = log [ x + sqrt(x*x-1) ]
33  * we have
34  * acosh(x) := log(x)+ln2, if x is large; else
35  * acosh(x) := log(2x-1/(sqrt(x*x-1)+x)) if x>2; else
36  * acosh(x) := log1p(t+sqrt(2.0*t+t*t)); where t=x-1.
37  *
38  * Special cases:
39  * acosh(x) is NaN with signal if x<1.
40  * acosh(NaN) is NaN without signal.
41  */
42 
43 #ifdef POK_NEEDS_LIBMATH
44 
45 #include <libm.h>
46 #include "math_private.h"
47 
48 static const double
49 one = 1.0,
50 ln2 = 6.93147180559945286227e-01; /* 0x3FE62E42, 0xFEFA39EF */
51 
52 double
53 __ieee754_acosh(double x)
54 {
55  double t;
56  int32_t hx;
57  uint32_t lx;
58  EXTRACT_WORDS(hx,lx,x);
59  if(hx<0x3ff00000) { /* x < 1 */
60  return (x-x)/(x-x);
61  } else if(hx >=0x41b00000) { /* x > 2**28 */
62  if(hx >=0x7ff00000) { /* x is inf of NaN */
63  return x+x;
64  } else
65  return __ieee754_log(x)+ln2; /* acosh(huge)=log(2x) */
66  } else if(((hx-0x3ff00000)|lx)==0) {
67  return 0.0; /* acosh(1) = 0 */
68  } else if (hx > 0x40000000) { /* 2**28 > x > 2 */
69  t=x*x;
70  return __ieee754_log(2.0*x-one/(x+__ieee754_sqrt(t-one)));
71  } else { /* 1<x<2 */
72  t = x-one;
73  return log1p(t+sqrt(2.0*t+t*t));
74  }
75 }
76 
77 #endif