5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
24 */
25 /*
26 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
27 * Use is subject to license terms.
28 */
29
30 #pragma weak __cexpl = cexpl
31
32 #include "libm.h" /* expl/isinfl/iszerol/scalbnl/sincosl */
33 #include "complex_wrapper.h"
34
35 extern int isinfl(long double);
36 extern int iszerol(long double);
37
38 /* INDENT OFF */
39 static const long double zero = 0.0L;
40 /* INDENT ON */
41
42 ldcomplex
43 cexpl(ldcomplex z) {
44 ldcomplex ans;
45 long double x, y, t, c, s;
46 int n, ix, iy, hx, hy;
47
48 x = LD_RE(z);
49 y = LD_IM(z);
50 hx = HI_XWORD(x);
51 hy = HI_XWORD(y);
52 ix = hx & 0x7fffffff;
53 iy = hy & 0x7fffffff;
54 if (iszerol(y)) { /* y = 0 */
55 LD_RE(ans) = expl(x);
56 LD_IM(ans) = y;
57 } else if (isinfl(x)) { /* x is +-inf */
58 if (hx < 0) {
59 if (iy >= 0x7fff0000) {
60 LD_RE(ans) = zero;
61 LD_IM(ans) = zero;
62 } else {
63 sincosl(y, &s, &c);
64 LD_RE(ans) = zero * c;
65 LD_IM(ans) = zero * s;
66 }
67 } else {
68 if (iy >= 0x7fff0000) {
69 LD_RE(ans) = x;
70 LD_IM(ans) = y - y;
71 } else {
72 (void) sincosl(y, &s, &c);
73 LD_RE(ans) = x * c;
74 LD_IM(ans) = x * s;
75 }
76 }
77 } else {
78 (void) sincosl(y, &s, &c);
79 if (ix >= 0x400C62E4) { /* |x| > 11356.52... ~ log(2**16384) */
80 t = __k_cexpl(x, &n);
81 LD_RE(ans) = scalbnl(t * c, n);
82 LD_IM(ans) = scalbnl(t * s, n);
83 } else {
84 t = expl(x);
85 LD_RE(ans) = t * c;
86 LD_IM(ans) = t * s;
87 }
88 }
89 return (ans);
90 }
|
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
24 */
25
26 /*
27 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
28 * Use is subject to license terms.
29 */
30
31 #pragma weak __cexpl = cexpl
32
33 #include "libm.h" /* expl/isinfl/iszerol/scalbnl/sincosl */
34 #include "complex_wrapper.h"
35
36 extern int isinfl(long double);
37 extern int iszerol(long double);
38
39 static const long double zero = 0.0L;
40
41
42 ldcomplex
43 cexpl(ldcomplex z)
44 {
45 ldcomplex ans;
46 long double x, y, t, c, s;
47 int n, ix, iy, hx, hy;
48
49 x = LD_RE(z);
50 y = LD_IM(z);
51 hx = HI_XWORD(x);
52 hy = HI_XWORD(y);
53 ix = hx & 0x7fffffff;
54 iy = hy & 0x7fffffff;
55
56 if (iszerol(y)) { /* y = 0 */
57 LD_RE(ans) = expl(x);
58 LD_IM(ans) = y;
59 } else if (isinfl(x)) { /* x is +-inf */
60 if (hx < 0) {
61 if (iy >= 0x7fff0000) {
62 LD_RE(ans) = zero;
63 LD_IM(ans) = zero;
64 } else {
65 sincosl(y, &s, &c);
66 LD_RE(ans) = zero * c;
67 LD_IM(ans) = zero * s;
68 }
69 } else {
70 if (iy >= 0x7fff0000) {
71 LD_RE(ans) = x;
72 LD_IM(ans) = y - y;
73 } else {
74 (void) sincosl(y, &s, &c);
75 LD_RE(ans) = x * c;
76 LD_IM(ans) = x * s;
77 }
78 }
79 } else {
80 (void) sincosl(y, &s, &c);
81
82 if (ix >= 0x400C62E4) { /* |x| > 11356.52... ~ log(2**16384) */
83 t = __k_cexpl(x, &n);
84 LD_RE(ans) = scalbnl(t * c, n);
85 LD_IM(ans) = scalbnl(t * s, n);
86 } else {
87 t = expl(x);
88 LD_RE(ans) = t * c;
89 LD_IM(ans) = t * s;
90 }
91 }
92
93 return (ans);
94 }
|