comparison libquadmath/math/ccoshq.c @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents 04ced10e8804
children
comparison
equal deleted inserted replaced
131:84e7813d76e9 145:1830386684a0
1 /* Complex cosine hyperbole function for complex __float128. 1 /* Complex cosine hyperbolic function for float types.
2 Copyright (C) 1997-2012 Free Software Foundation, Inc. 2 Copyright (C) 1997-2018 Free Software Foundation, Inc.
3 This file is part of the GNU C Library. 3 This file is part of the GNU C Library.
4 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997. 4 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
5 5
6 The GNU C Library is free software; you can redistribute it and/or 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 7 modify it under the terms of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see 17 License along with the GNU C Library; if not, see
18 <http://www.gnu.org/licenses/>. */ 18 <http://www.gnu.org/licenses/>. */
19 19
20 #include "quadmath-imp.h" 20 #include "quadmath-imp.h"
21 21
22 #ifdef HAVE_FENV_H
23 # include <fenv.h>
24 #endif
25
26
27 __complex128 22 __complex128
28 ccoshq (__complex128 x) 23 ccoshq (__complex128 x)
29 { 24 {
30 __complex128 retval; 25 __complex128 retval;
31 int rcls = fpclassifyq (__real__ x); 26 int rcls = fpclassifyq (__real__ x);
32 int icls = fpclassifyq (__imag__ x); 27 int icls = fpclassifyq (__imag__ x);
33 28
34 if (__builtin_expect (rcls >= QUADFP_ZERO, 1)) 29 if (__glibc_likely (rcls >= QUADFP_ZERO))
35 { 30 {
36 /* Real part is finite. */ 31 /* Real part is finite. */
37 if (__builtin_expect (icls >= QUADFP_ZERO, 1)) 32 if (__glibc_likely (icls >= QUADFP_ZERO))
38 { 33 {
39 /* Imaginary part is finite. */ 34 /* Imaginary part is finite. */
40 const int t = (int) ((FLT128_MAX_EXP - 1) * M_LN2q); 35 const int t = (int) ((FLT128_MAX_EXP - 1) * M_LN2q);
41 __float128 sinix, cosix; 36 __float128 sinix, cosix;
42 37
43 if (__builtin_expect (icls != QUADFP_SUBNORMAL, 1)) 38 if (__glibc_likely (fabsq (__imag__ x) > FLT128_MIN))
44 { 39 {
45 sincosq (__imag__ x, &sinix, &cosix); 40 sincosq (__imag__ x, &sinix, &cosix);
46 } 41 }
47 else 42 else
48 { 43 {
49 sinix = __imag__ x; 44 sinix = __imag__ x;
50 cosix = 1.0Q; 45 cosix = 1;
51 } 46 }
52 47
53 if (fabsq (__real__ x) > t) 48 if (fabsq (__real__ x) > t)
54 { 49 {
55 __float128 exp_t = expq (t); 50 __float128 exp_t = expq (t);
56 __float128 rx = fabsq (__real__ x); 51 __float128 rx = fabsq (__real__ x);
57 if (signbitq (__real__ x)) 52 if (signbitq (__real__ x))
58 sinix = -sinix; 53 sinix = -sinix;
59 rx -= t; 54 rx -= t;
60 sinix *= exp_t / 2.0Q; 55 sinix *= exp_t / 2;
61 cosix *= exp_t / 2.0Q; 56 cosix *= exp_t / 2;
62 if (rx > t) 57 if (rx > t)
63 { 58 {
64 rx -= t; 59 rx -= t;
65 sinix *= exp_t; 60 sinix *= exp_t;
66 cosix *= exp_t; 61 cosix *= exp_t;
81 else 76 else
82 { 77 {
83 __real__ retval = coshq (__real__ x) * cosix; 78 __real__ retval = coshq (__real__ x) * cosix;
84 __imag__ retval = sinhq (__real__ x) * sinix; 79 __imag__ retval = sinhq (__real__ x) * sinix;
85 } 80 }
81
82 math_check_force_underflow_complex (retval);
86 } 83 }
87 else 84 else
88 { 85 {
89 __imag__ retval = __real__ x == 0.0Q ? 0.0Q : nanq (""); 86 __imag__ retval = __real__ x == 0 ? 0 : nanq ("");
90 __real__ retval = nanq ("") + nanq (""); 87 __real__ retval = __imag__ x - __imag__ x;
91 88 }
92 #ifdef HAVE_FENV_H
93 if (icls == QUADFP_INFINITE)
94 feraiseexcept (FE_INVALID);
95 #endif
96 }
97 } 89 }
98 else if (rcls == QUADFP_INFINITE) 90 else if (rcls == QUADFP_INFINITE)
99 { 91 {
100 /* Real part is infinite. */ 92 /* Real part is infinite. */
101 if (__builtin_expect (icls > QUADFP_ZERO, 1)) 93 if (__glibc_likely (icls > QUADFP_ZERO))
102 { 94 {
103 /* Imaginary part is finite. */ 95 /* Imaginary part is finite. */
104 __float128 sinix, cosix; 96 __float128 sinix, cosix;
105 97
106 if (__builtin_expect (icls != QUADFP_SUBNORMAL, 1)) 98 if (__glibc_likely (fabsq (__imag__ x) > FLT128_MIN))
107 { 99 {
108 sincosq (__imag__ x, &sinix, &cosix); 100 sincosq (__imag__ x, &sinix, &cosix);
109 } 101 }
110 else 102 else
111 { 103 {
112 sinix = __imag__ x; 104 sinix = __imag__ x;
113 cosix = 1.0Q; 105 cosix = 1;
114 } 106 }
115 107
116 __real__ retval = copysignq (HUGE_VALQ, cosix); 108 __real__ retval = copysignq (HUGE_VALQ, cosix);
117 __imag__ retval = (copysignq (HUGE_VALQ, sinix) 109 __imag__ retval = (copysignq (HUGE_VALQ, sinix)
118 * copysignq (1.0Q, __real__ x)); 110 * copysignq (1, __real__ x));
119 } 111 }
120 else if (icls == QUADFP_ZERO) 112 else if (icls == QUADFP_ZERO)
121 { 113 {
122 /* Imaginary part is 0.0. */ 114 /* Imaginary part is 0.0. */
123 __real__ retval = HUGE_VALQ; 115 __real__ retval = HUGE_VALQ;
124 __imag__ retval = __imag__ x * copysignq (1.0Q, __real__ x); 116 __imag__ retval = __imag__ x * copysignq (1, __real__ x);
125 } 117 }
126 else 118 else
127 { 119 {
128 /* The addition raises the invalid exception. */
129 __real__ retval = HUGE_VALQ; 120 __real__ retval = HUGE_VALQ;
130 __imag__ retval = nanq ("") + nanq (""); 121 __imag__ retval = __imag__ x - __imag__ x;
131 122 }
132 #ifdef HAVE_FENV_H
133 if (icls == QUADFP_INFINITE)
134 feraiseexcept (FE_INVALID);
135 #endif
136 }
137 } 123 }
138 else 124 else
139 { 125 {
140 __real__ retval = nanq (""); 126 __real__ retval = nanq ("");
141 __imag__ retval = __imag__ x == 0.0 ? __imag__ x : nanq (""); 127 __imag__ retval = __imag__ x == 0 ? __imag__ x : nanq ("");
142 } 128 }
143 129
144 return retval; 130 return retval;
145 } 131 }