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 __clogl = clogl
31
32 #include "libm.h" /* atan2l/fabsl/isinfl/log1pl/logl/__k_clog_rl */
33 #include "complex_wrapper.h"
34 #include "longdouble.h"
35
36 #if defined(__sparc)
37 #define SIGP7 120
38 #define HSIGP7 60
39 #elif defined(__x86)
40 #define SIGP7 70
41 #define HSIGP7 35
42 #endif
43
44 /* INDENT OFF */
45 static const long double zero = 0.0L, half = 0.5L, one = 1.0L;
46 /* INDENT ON */
47
48 ldcomplex
49 clogl(ldcomplex z) {
50 ldcomplex ans;
51 long double x, y, t, ax, ay;
52 int n, ix, iy, hx, hy;
53
54 x = LD_RE(z);
55 y = LD_IM(z);
56 hx = HI_XWORD(x);
57 hy = HI_XWORD(y);
58 ix = hx & 0x7fffffff;
59 iy = hy & 0x7fffffff;
60 ay = fabsl(y);
61 ax = fabsl(x);
62 LD_IM(ans) = atan2l(y, x);
63 if (ix < iy || (ix == iy && ix < 0x7fff0000 && ax < ay)) {
64 /* swap x and y to force ax>=ay */
65 t = ax;
66 ax = ay;
67 ay = t;
68 n = ix, ix = iy;
69 iy = n;
70 }
71 n = (ix - iy) >> 16;
72 if (ix >= 0x7fff0000) { /* x or y is Inf or NaN */
73 if (isinfl(ax))
74 LD_RE(ans) = ax;
75 else if (isinfl(ay))
76 LD_RE(ans) = ay;
77 else
78 LD_RE(ans) = ax + ay;
79 } else if (ay == zero)
80 LD_RE(ans) = logl(ax);
81 else if (((0x3fffffff - ix) ^ (ix - 0x3ffe0000)) >= 0) {
82 /* 0.5 <= x < 2 */
83 if (ix >= 0x3fff0000) {
84 if (ax == one)
85 LD_RE(ans) = half * log1pl(ay * ay);
86 else if (n >= SIGP7)
87 LD_RE(ans) = logl(ax);
88 else
89 LD_RE(ans) = half * (log1pl(ay * ay + (ax -
90 one) * (ax + one)));
91 } else if (n >= SIGP7)
92 LD_RE(ans) = logl(ax);
93 else
94 LD_RE(ans) = __k_clog_rl(x, y, &t);
95 } else if (n >= HSIGP7)
96 LD_RE(ans) = logl(ax);
97 else if (ix < 0x5f3f0000 && iy >= 0x20bf0000)
98 /* 2**-8000 < y < x < 2**8000 */
99 LD_RE(ans) = half * logl(ax * ax + ay * ay);
100 else {
101 t = ay / ax;
102 LD_RE(ans) = logl(ax) + half * log1pl(t * t);
103 }
104 return (ans);
105 }
|
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 __clogl = clogl
32
33 #include "libm.h" /* atan2l/fabsl/isinfl/log1pl/logl/__k_clog_rl */
34 #include "complex_wrapper.h"
35 #include "longdouble.h"
36
37 #if defined(__sparc)
38 #define SIGP7 120
39 #define HSIGP7 60
40 #elif defined(__x86)
41 #define SIGP7 70
42 #define HSIGP7 35
43 #endif
44
45 static const long double zero = 0.0L, half = 0.5L, one = 1.0L;
46
47
48 ldcomplex
49 clogl(ldcomplex z)
50 {
51 ldcomplex ans;
52 long double x, y, t, ax, ay;
53 int n, ix, iy, hx, hy;
54
55 x = LD_RE(z);
56 y = LD_IM(z);
57 hx = HI_XWORD(x);
58 hy = HI_XWORD(y);
59 ix = hx & 0x7fffffff;
60 iy = hy & 0x7fffffff;
61 ay = fabsl(y);
62 ax = fabsl(x);
63 LD_IM(ans) = atan2l(y, x);
64
65 if (ix < iy || (ix == iy && ix < 0x7fff0000 && ax < ay)) {
66 /* swap x and y to force ax>=ay */
67 t = ax;
68 ax = ay;
69 ay = t;
70 n = ix, ix = iy;
71 iy = n;
72 }
73
74 n = (ix - iy) >> 16;
75
76 if (ix >= 0x7fff0000) { /* x or y is Inf or NaN */
77 if (isinfl(ax))
78 LD_RE(ans) = ax;
79 else if (isinfl(ay))
80 LD_RE(ans) = ay;
81 else
82 LD_RE(ans) = ax + ay;
83 } else if (ay == zero) {
84 LD_RE(ans) = logl(ax);
85 } else if (((0x3fffffff - ix) ^ (ix - 0x3ffe0000)) >= 0) {
86 /* 0.5 <= x < 2 */
87 if (ix >= 0x3fff0000) {
88 if (ax == one)
89 LD_RE(ans) = half * log1pl(ay * ay);
90 else if (n >= SIGP7)
91 LD_RE(ans) = logl(ax);
92 else
93 LD_RE(ans) = half * (log1pl(ay * ay + (ax -
94 one) * (ax + one)));
95 } else if (n >= SIGP7) {
96 LD_RE(ans) = logl(ax);
97 } else {
98 LD_RE(ans) = __k_clog_rl(x, y, &t);
99 }
100 } else if (n >= HSIGP7) {
101 LD_RE(ans) = logl(ax);
102 } else if (ix < 0x5f3f0000 && iy >= 0x20bf0000) {
103 /* 2**-8000 < y < x < 2**8000 */
104 LD_RE(ans) = half * logl(ax * ax + ay * ay);
105 } else {
106 t = ay / ax;
107 LD_RE(ans) = logl(ax) + half * log1pl(t * t);
108 }
109
110 return (ans);
111 }
|