]>
Commit | Line | Data |
---|---|---|
bc6dd76e | 1 | /* Complex exponential function. m68k fpu version |
04277e02 | 2 | Copyright (C) 1997-2019 Free Software Foundation, Inc. |
bc6dd76e UD |
3 | This file is part of the GNU C Library. |
4 | Contributed by Andreas Schwab <schwab@issan.informatik.uni-dortmund.de> | |
5 | ||
6 | The GNU C Library is free software; you can redistribute it and/or | |
3214b89b AJ |
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. | |
bc6dd76e UD |
10 | |
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 | |
3214b89b | 14 | Lesser General Public License for more details. |
bc6dd76e | 15 | |
3214b89b | 16 | You should have received a copy of the GNU Lesser General Public |
ab84e3ff | 17 | License along with the GNU C Library. If not, see |
5a82c748 | 18 | <https://www.gnu.org/licenses/>. */ |
bc6dd76e | 19 | |
2f6ba762 | 20 | #include <float.h> |
bc6dd76e UD |
21 | #include <complex.h> |
22 | #include <math.h> | |
5da9d124 | 23 | #include "mathimpl.h" |
bc6dd76e | 24 | |
bc6dd76e | 25 | #define CONCATX(a,b) __CONCAT(a,b) |
feb62dda | 26 | #define s(name) M_SUF (name) |
bc6dd76e UD |
27 | #define m81(func) __m81_u(s(func)) |
28 | ||
feb62dda PM |
29 | CFLOAT |
30 | s(__cexp) (CFLOAT x) | |
bc6dd76e | 31 | { |
feb62dda | 32 | CFLOAT retval; |
e7af313d UD |
33 | unsigned long ix_cond; |
34 | ||
35 | ix_cond = __m81_test (__imag__ x); | |
bc6dd76e | 36 | |
e7af313d | 37 | if ((ix_cond & (__M81_COND_NAN|__M81_COND_INF)) == 0) |
bc6dd76e | 38 | { |
e7af313d | 39 | /* Imaginary part is finite. */ |
2f6ba762 | 40 | unsigned long rx_cond = __m81_test (__real__ x); |
e7af313d | 41 | |
2f6ba762 | 42 | if ((rx_cond & (__M81_COND_NAN|__M81_COND_INF)) == 0) |
bc6dd76e | 43 | { |
2f6ba762 AS |
44 | const int t = (int) ((LDBL_MAX_EXP - 1) * M_LN2l); |
45 | long double sin_ix, cos_ix, exp_val; | |
46 | ||
47 | __m81_u (__sincosl) (__imag__ x, &sin_ix, &cos_ix); | |
48 | ||
49 | if (__real__ x > t) | |
50 | { | |
51 | long double exp_t = __m81_u(__ieee754_expl) (t); | |
52 | __real__ x -= t; | |
53 | sin_ix *= exp_t; | |
54 | cos_ix *= exp_t; | |
55 | if (__real__ x > t) | |
56 | { | |
57 | __real__ x -= t; | |
58 | sin_ix *= exp_t; | |
59 | cos_ix *= exp_t; | |
60 | } | |
61 | } | |
62 | ||
63 | exp_val = __m81_u(__ieee754_expl) (__real__ x); | |
64 | __real__ retval = exp_val * cos_ix; | |
e7af313d UD |
65 | if (ix_cond & __M81_COND_ZERO) |
66 | __imag__ retval = __imag__ x; | |
67 | else | |
2f6ba762 | 68 | __imag__ retval = exp_val * sin_ix; |
e7af313d UD |
69 | } |
70 | else | |
71 | { | |
72 | /* Compute the sign of the result. */ | |
2f6ba762 | 73 | long double remainder, pi_2; |
e7af313d | 74 | int quadrant; |
bc6dd76e | 75 | |
2f6ba762 AS |
76 | if ((rx_cond & (__M81_COND_NAN|__M81_COND_NEG)) == __M81_COND_NEG) |
77 | __real__ retval = __imag__ retval = 0.0; | |
78 | else | |
79 | __real__ retval = __imag__ retval = __real__ x; | |
e7af313d UD |
80 | __asm ("fmovecr %#0,%0\n\tfscale%.w %#-1,%0" : "=f" (pi_2)); |
81 | __asm ("fmod%.x %2,%0\n\tfmove%.l %/fpsr,%1" | |
82 | : "=f" (remainder), "=dm" (quadrant) | |
83 | : "f" (pi_2), "0" (__imag__ x)); | |
84 | quadrant = (quadrant >> 16) & 0x83; | |
85 | if (quadrant & 0x80) | |
86 | quadrant ^= 0x83; | |
87 | switch (quadrant) | |
45b0751e | 88 | { |
e7af313d UD |
89 | default: |
90 | break; | |
91 | case 1: | |
92 | __real__ retval = -__real__ retval; | |
93 | break; | |
94 | case 2: | |
95 | __real__ retval = -__real__ retval; | |
e0cb7b61 | 96 | /* Fall through. */ |
e7af313d UD |
97 | case 3: |
98 | __imag__ retval = -__imag__ retval; | |
99 | break; | |
45b0751e | 100 | } |
2f6ba762 | 101 | if (ix_cond & __M81_COND_ZERO && (rx_cond & __M81_COND_NAN) == 0) |
e7af313d | 102 | __imag__ retval = __imag__ x; |
bc6dd76e | 103 | } |
bc6dd76e | 104 | } |
e7af313d | 105 | else |
bc6dd76e | 106 | { |
e7af313d | 107 | unsigned long rx_cond = __m81_test (__real__ x); |
45b0751e | 108 | |
e7af313d UD |
109 | if (rx_cond & __M81_COND_INF) |
110 | { | |
111 | /* Real part is infinite. */ | |
112 | if (rx_cond & __M81_COND_NEG) | |
45b0751e | 113 | { |
e7af313d UD |
114 | __real__ retval = __imag__ retval = 0.0; |
115 | if (ix_cond & __M81_COND_NEG) | |
116 | __imag__ retval = -__imag__ retval; | |
45b0751e | 117 | } |
bc6dd76e UD |
118 | else |
119 | { | |
e7af313d UD |
120 | __real__ retval = __real__ x; |
121 | __imag__ retval = __imag__ x - __imag__ x; | |
bc6dd76e UD |
122 | } |
123 | } | |
bc6dd76e | 124 | else |
e7af313d | 125 | __real__ retval = __imag__ retval = __imag__ x - __imag__ x; |
bc6dd76e | 126 | } |
bc6dd76e UD |
127 | |
128 | return retval; | |
129 | } | |
faec6323 | 130 | declare_mgen_alias (__cexp, cexp) |