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/>. */
23 #include <math_private.h>
24 #include <math-underflow.h>
28 M_DECL_FUNC (__cexp
) (CFLOAT x
)
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
));
43 if (__glibc_likely (M_FABS (__imag__ x
) > M_MIN
))
45 M_SINCOS (__imag__ x
, &sinix
, &cosix
);
55 FLOAT exp_t
= M_EXP (t
);
68 /* Overflow (original real part of x > 3t). */
69 __real__ retval
= M_MAX
* cosix
;
70 __imag__ retval
= M_MAX
* sinix
;
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
);
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
;
100 /* Imaginary part is 0.0. */
101 __real__ retval
= value
;
102 __imag__ retval
= __imag__ x
;
108 if (__glibc_likely (M_FABS (__imag__ x
) > M_MIN
))
110 M_SINCOS (__imag__ x
, &sinix
, &cosix
);
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
;
130 __imag__ retval
= M_COPYSIGN (0, __imag__ x
);
135 /* If the real part is NaN the result is NaN + iNaN unless the
136 imaginary part is zero. */
137 __real__ retval
= M_NAN
;
139 __imag__ retval
= __imag__ x
;
142 __imag__ retval
= M_NAN
;
144 if (rcls
!= FP_NAN
|| icls
!= FP_NAN
)
145 feraiseexcept (FE_INVALID
);
151 declare_mgen_alias (__cexp
, cexp
)