Revert "nscd: don't fork twice"
[glibc.git] / math / s_casinhl.c
blobd7c74593e4c5e9fd9c562871ee0667dc94c93832
1 /* Return arc hyperbole sine for long double value.
2 Copyright (C) 1997-2013 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <http://www.gnu.org/licenses/>. */
20 #include <complex.h>
21 #include <math.h>
22 #include <math_private.h>
23 #include <float.h>
25 /* To avoid spurious overflows, use this definition to treat IBM long
26 double as approximating an IEEE-style format. */
27 #if LDBL_MANT_DIG == 106
28 # undef LDBL_EPSILON
29 # define LDBL_EPSILON 0x1p-106L
30 #endif
32 __complex__ long double
33 __casinhl (__complex__ long double x)
35 __complex__ long double res;
36 int rcls = fpclassify (__real__ x);
37 int icls = fpclassify (__imag__ x);
39 if (rcls <= FP_INFINITE || icls <= FP_INFINITE)
41 if (icls == FP_INFINITE)
43 __real__ res = __copysignl (HUGE_VALL, __real__ x);
45 if (rcls == FP_NAN)
46 __imag__ res = __nanl ("");
47 else
48 __imag__ res = __copysignl (rcls >= FP_ZERO ? M_PI_2l : M_PI_4l,
49 __imag__ x);
51 else if (rcls <= FP_INFINITE)
53 __real__ res = __real__ x;
54 if ((rcls == FP_INFINITE && icls >= FP_ZERO)
55 || (rcls == FP_NAN && icls == FP_ZERO))
56 __imag__ res = __copysignl (0.0, __imag__ x);
57 else
58 __imag__ res = __nanl ("");
60 else
62 __real__ res = __nanl ("");
63 __imag__ res = __nanl ("");
66 else if (rcls == FP_ZERO && icls == FP_ZERO)
68 res = x;
70 else
72 long double rx, ix;
73 __complex__ long double y;
75 /* Avoid cancellation by reducing to the first quadrant. */
76 rx = fabsl (__real__ x);
77 ix = fabsl (__imag__ x);
79 if (rx >= 1.0L / LDBL_EPSILON || ix >= 1.0L / LDBL_EPSILON)
81 /* For large x in the first quadrant, x + csqrt (1 + x * x)
82 is sufficiently close to 2 * x to make no significant
83 difference to the result; avoid possible overflow from
84 the squaring and addition. */
85 __real__ y = rx;
86 __imag__ y = ix;
87 res = __clogl (y);
88 __real__ res += M_LN2l;
90 else
92 __real__ y = (rx - ix) * (rx + ix) + 1.0;
93 __imag__ y = 2.0 * rx * ix;
95 y = __csqrtl (y);
97 __real__ y += rx;
98 __imag__ y += ix;
100 res = __clogl (y);
103 /* Give results the correct sign for the original argument. */
104 __real__ res = __copysignl (__real__ res, __real__ x);
105 __imag__ res = __copysignl (__imag__ res, __imag__ x);
108 return res;
110 weak_alias (__casinhl, casinhl)