x86-64: Skip zero length in __mem[pcpy|move|set]_erms
[glibc.git] / math / s_cexp_template.c
blob5fdab1e5ac3fa7b465b408e1230d1e998b22cb36
1 /* Return value of complex exponential function for a float type.
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 <complex.h>
21 #include <fenv.h>
22 #include <math.h>
23 #include <math_private.h>
24 #include <math-underflow.h>
25 #include <float.h>
27 CFLOAT
28 M_DECL_FUNC (__cexp) (CFLOAT x)
30 CFLOAT retval;
31 int rcls = fpclassify (__real__ x);
32 int icls = fpclassify (__imag__ x);
34 if (__glibc_likely (rcls >= FP_ZERO))
36 /* Real part is finite. */
37 if (__glibc_likely (icls >= FP_ZERO))
39 /* Imaginary part is finite. */
40 const int t = (int) ((M_MAX_EXP - 1) * M_MLIT (M_LN2));
41 FLOAT sinix, cosix;
43 if (__glibc_likely (M_FABS (__imag__ x) > M_MIN))
45 M_SINCOS (__imag__ x, &sinix, &cosix);
47 else
49 sinix = __imag__ x;
50 cosix = 1;
53 if (__real__ x > t)
55 FLOAT exp_t = M_EXP (t);
56 __real__ x -= t;
57 sinix *= exp_t;
58 cosix *= exp_t;
59 if (__real__ x > t)
61 __real__ x -= t;
62 sinix *= exp_t;
63 cosix *= exp_t;
66 if (__real__ x > t)
68 /* Overflow (original real part of x > 3t). */
69 __real__ retval = M_MAX * cosix;
70 __imag__ retval = M_MAX * sinix;
72 else
74 FLOAT exp_val = M_EXP (__real__ x);
75 __real__ retval = exp_val * cosix;
76 __imag__ retval = exp_val * sinix;
78 math_check_force_underflow_complex (retval);
80 else
82 /* If the imaginary part is +-inf or NaN and the real part
83 is not +-inf the result is NaN + iNaN. */
84 __real__ retval = M_NAN;
85 __imag__ retval = M_NAN;
87 feraiseexcept (FE_INVALID);
90 else if (__glibc_likely (rcls == FP_INFINITE))
92 /* Real part is infinite. */
93 if (__glibc_likely (icls >= FP_ZERO))
95 /* Imaginary part is finite. */
96 FLOAT value = signbit (__real__ x) ? 0 : M_HUGE_VAL;
98 if (icls == FP_ZERO)
100 /* Imaginary part is 0.0. */
101 __real__ retval = value;
102 __imag__ retval = __imag__ x;
104 else
106 FLOAT sinix, cosix;
108 if (__glibc_likely (M_FABS (__imag__ x) > M_MIN))
110 M_SINCOS (__imag__ x, &sinix, &cosix);
112 else
114 sinix = __imag__ x;
115 cosix = 1;
118 __real__ retval = M_COPYSIGN (value, cosix);
119 __imag__ retval = M_COPYSIGN (value, sinix);
122 else if (signbit (__real__ x) == 0)
124 __real__ retval = M_HUGE_VAL;
125 __imag__ retval = __imag__ x - __imag__ x;
127 else
129 __real__ retval = 0;
130 __imag__ retval = M_COPYSIGN (0, __imag__ x);
133 else
135 /* If the real part is NaN the result is NaN + iNaN unless the
136 imaginary part is zero. */
137 __real__ retval = M_NAN;
138 if (icls == FP_ZERO)
139 __imag__ retval = __imag__ x;
140 else
142 __imag__ retval = M_NAN;
144 if (rcls != FP_NAN || icls != FP_NAN)
145 feraiseexcept (FE_INVALID);
149 return retval;
151 declare_mgen_alias (__cexp, cexp)