dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / lib / libm / common / m9x / frexpl.c
blobd2639abc077ad6d40de2e471ce2f7af1cdf6d6ed
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
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.
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]
19 * CDDL HEADER END
23 * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
26 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
27 * Use is subject to license terms.
30 #pragma weak frexpl = __frexpl
32 #include "libm.h"
34 #if defined(__sparc)
36 long double
37 __frexpl(long double x, int *exp) {
38 union {
39 unsigned i[4];
40 long double q;
41 } xx;
42 unsigned hx;
43 int e, s;
45 xx.q = x;
46 hx = xx.i[0] & ~0x80000000;
48 if (hx >= 0x7fff0000) { /* x is infinite or NaN */
49 *exp = 0;
50 return (x);
53 e = 0;
54 if (hx < 0x00010000) { /* x is subnormal or zero */
55 if ((hx | xx.i[1] | xx.i[2] | xx.i[3]) == 0) {
56 *exp = 0;
57 return (x);
60 /* normalize x */
61 s = xx.i[0] & 0x80000000;
62 while ((hx | (xx.i[1] & 0xffff0000)) == 0) {
63 hx = xx.i[1];
64 xx.i[1] = xx.i[2];
65 xx.i[2] = xx.i[3];
66 xx.i[3] = 0;
67 e -= 32;
69 while (hx < 0x10000) {
70 hx = (hx << 1) | (xx.i[1] >> 31);
71 xx.i[1] = (xx.i[1] << 1) | (xx.i[2] >> 31);
72 xx.i[2] = (xx.i[2] << 1) | (xx.i[3] >> 31);
73 xx.i[3] <<= 1;
74 e--;
76 xx.i[0] = s | hx;
79 /* now xx.q is normal */
80 xx.i[0] = (xx.i[0] & ~0x7fff0000) | 0x3ffe0000;
81 *exp = e + (hx >> 16) - 0x3ffe;
82 return (xx.q);
85 #elif defined(__x86)
87 long double
88 __frexpl(long double x, int *exp) {
89 union {
90 unsigned i[3];
91 long double e;
92 } xx;
93 unsigned hx;
94 int e;
96 xx.e = x;
97 hx = xx.i[2] & 0x7fff;
99 if (hx >= 0x7fff) { /* x is infinite or NaN */
100 *exp = 0;
101 return (x);
104 e = 0;
105 if (hx < 0x0001) { /* x is subnormal or zero */
106 if ((xx.i[0] | xx.i[1]) == 0) {
107 *exp = 0;
108 return (x);
111 /* normalize x */
112 xx.e *= 18446744073709551616.0L; /* 2^64 */
113 hx = xx.i[2] & 0x7fff;
114 e = -64;
117 /* now xx.e is normal */
118 xx.i[2] = (xx.i[2] & 0x8000) | 0x3ffe;
119 *exp = e + hx - 0x3ffe;
120 return (xx.e);
123 #else
124 #error Unknown architecture
125 #endif