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]
22 * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
25 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
26 * Use is subject to license terms.
29 #pragma weak __scalbn = scalbn
37 twom54
= 5.5511151231257827021181583404541015625e-17;
40 static const double two52
= 4503599627370496.0;
43 * Normalize non-zero subnormal x and return biased exponent of x in [-51,0]
46 ilogb_biased(unsigned *px
) {
48 unsigned v
= px
[HIWORD
] & ~0x80000000, w
= px
[LOWORD
], t
= v
;
61 s
-= (0xffffaa50 >> t
) & 0x3;
63 v
= (v
<< s
) | w
>> (32 - s
);
69 px
[HIWORD
] = (px
[HIWORD
] & 0x80000000) | v
;
73 #endif /* defined(__x86) */
76 scalbn(double x
, int n
) {
81 hx
= ix
& ~0x80000000;
84 if (k
== 0x7ff) /* x is inf or NaN */
88 if ((hx
| px
[LOWORD
]) == 0 || n
== 0)
93 k
= ((ix
& ~0x80000000) >> 20) - 52;
95 k
= ilogb_biased((unsigned *)px
);
98 /* now k is in the range -51..0 */
100 if (k
> n
) /* integer overflow occurred */
103 /* k is in the range 1..1023 */
105 if (k
< n
) /* integer overflow occurred */
110 return (huge
* ((ix
< 0)? -huge
: huge
));
113 return (tiny
* ((ix
< 0)? -tiny
: tiny
));
115 px
[HIWORD
] = (ix
& ~0x7ff00000) | (k
<< 20);
118 px
[HIWORD
] = (ix
& ~0x7ff00000) | (k
<< 20);