POK
asinh.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 /* @(#)s_asinh.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 /* asinh(x)
30  * Method :
31  * Based on
32  * asinh(x) = sign(x) * log [ |x| + sqrt(x*x+1) ]
33  * we have
34  * asinh(x) := x if 1+x*x=1,
35  * := sign(x)*(log(x)+ln2)) for large |x|, else
36  * := sign(x)*log(2|x|+1/(|x|+sqrt(x*x+1))) if|x|>2, else
37  * := sign(x)*log1p(|x| + x^2/(1 + sqrt(1+x^2)))
38  */
39 
40 #ifdef POK_NEEDS_LIBMATH
41 
42 #include <types.h>
43 #include <libm.h>
44 #include "math_private.h"
45 
46 static const double
47 one = 1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */
48 ln2 = 6.93147180559945286227e-01, /* 0x3FE62E42, 0xFEFA39EF */
49 huge= 1.00000000000000000000e+300;
50 
51 double
52 asinh(double x)
53 {
54  double t,w;
55  int32_t hx,ix;
56  GET_HIGH_WORD(hx,x);
57  ix = hx&0x7fffffff;
58  if(ix>=0x7ff00000) return x+x; /* x is inf or NaN */
59  if(ix< 0x3e300000) { /* |x|<2**-28 */
60  if(huge+x>one) return x; /* return x inexact except 0 */
61  }
62  if(ix>0x41b00000) { /* |x| > 2**28 */
63  w = __ieee754_log(fabs(x))+ln2;
64  } else if (ix>0x40000000) { /* 2**28 > |x| > 2.0 */
65  t = fabs(x);
66  w = __ieee754_log(2.0*t+one/(__ieee754_sqrt(x*x+one)+t));
67  } else { /* 2.0 > |x| > 2**-28 */
68  t = x*x;
69  w =log1p(fabs(x)+t/(one+__ieee754_sqrt(one+t)));
70  }
71  if(hx>0) return w; else return -w;
72 }
73 
74 #endif
75