2016-07-14 Steven G. Kargl <kargl@gcc.gnu.org>
[official-gcc.git] / libquadmath / math / asinhq.c
blob9be0aa1f05326ac30e136dc55796ca0a58376c08
1 /* asinhq.c -- __float128 version of s_asinh.c.
2 * Conversion to long double by Ulrich Drepper,
3 * Cygnus Support, drepper@cygnus.com.
4 */
6 /*
7 * ====================================================
8 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
10 * Developed at SunPro, a Sun Microsystems, Inc. business.
11 * Permission to use, copy, modify, and distribute this
12 * software is freely granted, provided that this notice
13 * is preserved.
14 * ====================================================
17 /* asinhl(x)
18 * Method :
19 * Based on
20 * asinhl(x) = signl(x) * logl [ |x| + sqrtl(x*x+1) ]
21 * we have
22 * asinhl(x) := x if 1+x*x=1,
23 * := signl(x)*(logl(x)+ln2)) for large |x|, else
24 * := signl(x)*logl(2|x|+1/(|x|+sqrtl(x*x+1))) if|x|>2, else
25 * := signl(x)*log1pl(|x| + x^2/(1 + sqrtl(1+x^2)))
28 #include "quadmath-imp.h"
30 static const __float128
31 one = 1.0Q,
32 ln2 = 6.931471805599453094172321214581765681e-1Q,
33 huge = 1.0e+4900Q;
35 __float128
36 asinhq (__float128 x)
38 __float128 t, w;
39 int32_t ix, sign;
40 ieee854_float128 u;
42 u.value = x;
43 sign = u.words32.w0;
44 ix = sign & 0x7fffffff;
45 if (ix == 0x7fff0000)
46 return x + x; /* x is inf or NaN */
47 if (ix < 0x3fc70000)
48 { /* |x| < 2^ -56 */
49 if (huge + x > one)
50 return x; /* return x inexact except 0 */
52 u.words32.w0 = ix;
53 if (ix > 0x40350000)
54 { /* |x| > 2 ^ 54 */
55 w = logq (u.value) + ln2;
57 else if (ix >0x40000000)
58 { /* 2^ 54 > |x| > 2.0 */
59 t = u.value;
60 w = logq (2.0 * t + one / (sqrtq (x * x + one) + t));
62 else
63 { /* 2.0 > |x| > 2 ^ -56 */
64 t = x * x;
65 w = log1pq (u.value + t / (one + sqrtq (one + t)));
67 if (sign & 0x80000000)
68 return -w;
69 else
70 return w;