Add -gno-strict-dwarf to dg-options in various btf enum tests
[official-gcc.git] / libquadmath / math / csinq.c
bloba38da8eebc55ad78a62c3a006229e50a25f47964
1 /* Complex sine function for float types.
2 Copyright (C) 1997-2018 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 "quadmath-imp.h"
22 __complex128
23 csinq (__complex128 x)
25 __complex128 retval;
26 int negate = signbitq (__real__ x);
27 int rcls = fpclassifyq (__real__ x);
28 int icls = fpclassifyq (__imag__ x);
30 __real__ x = fabsq (__real__ x);
32 if (__glibc_likely (icls >= QUADFP_ZERO))
34 /* Imaginary part is finite. */
35 if (__glibc_likely (rcls >= QUADFP_ZERO))
37 /* Real part is finite. */
38 const int t = (int) ((FLT128_MAX_EXP - 1) * M_LN2q);
39 __float128 sinix, cosix;
41 if (__glibc_likely (__real__ x > FLT128_MIN))
43 sincosq (__real__ x, &sinix, &cosix);
45 else
47 sinix = __real__ x;
48 cosix = 1;
51 if (negate)
52 sinix = -sinix;
54 if (fabsq (__imag__ x) > t)
56 __float128 exp_t = expq (t);
57 __float128 ix = fabsq (__imag__ x);
58 if (signbitq (__imag__ x))
59 cosix = -cosix;
60 ix -= t;
61 sinix *= exp_t / 2;
62 cosix *= exp_t / 2;
63 if (ix > t)
65 ix -= t;
66 sinix *= exp_t;
67 cosix *= exp_t;
69 if (ix > t)
71 /* Overflow (original imaginary part of x > 3t). */
72 __real__ retval = FLT128_MAX * sinix;
73 __imag__ retval = FLT128_MAX * cosix;
75 else
77 __float128 exp_val = expq (ix);
78 __real__ retval = exp_val * sinix;
79 __imag__ retval = exp_val * cosix;
82 else
84 __real__ retval = coshq (__imag__ x) * sinix;
85 __imag__ retval = sinhq (__imag__ x) * cosix;
88 math_check_force_underflow_complex (retval);
90 else
92 if (icls == QUADFP_ZERO)
94 /* Imaginary part is 0.0. */
95 __real__ retval = __real__ x - __real__ x;
96 __imag__ retval = __imag__ x;
98 else
100 __real__ retval = nanq ("");
101 __imag__ retval = nanq ("");
103 feraiseexcept (FE_INVALID);
107 else if (icls == QUADFP_INFINITE)
109 /* Imaginary part is infinite. */
110 if (rcls == QUADFP_ZERO)
112 /* Real part is 0.0. */
113 __real__ retval = copysignq (0, negate ? -1 : 1);
114 __imag__ retval = __imag__ x;
116 else if (rcls > QUADFP_ZERO)
118 /* Real part is finite. */
119 __float128 sinix, cosix;
121 if (__glibc_likely (__real__ x > FLT128_MIN))
123 sincosq (__real__ x, &sinix, &cosix);
125 else
127 sinix = __real__ x;
128 cosix = 1;
131 __real__ retval = copysignq (HUGE_VALQ, sinix);
132 __imag__ retval = copysignq (HUGE_VALQ, cosix);
134 if (negate)
135 __real__ retval = -__real__ retval;
136 if (signbitq (__imag__ x))
137 __imag__ retval = -__imag__ retval;
139 else
141 __real__ retval = __real__ x - __real__ x;
142 __imag__ retval = HUGE_VALQ;
145 else
147 if (rcls == QUADFP_ZERO)
148 __real__ retval = copysignq (0, negate ? -1 : 1);
149 else
150 __real__ retval = nanq ("");
151 __imag__ retval = nanq ("");
154 return retval;