]>
git.saurik.com Git - apple/libc.git/blob - gdtoa/_ldbl_util.c
2 * Copyright (c) 2004, 2008 Apple Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http:www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
24 #include <sys/cdefs.h>
33 #define DBL_BIAS (DBL_MAX_EXP - 1)
34 #define DBL_SUBEXP (-DBL_BIAS + 1)
35 #define LL_BITS (8 * sizeof(int64_t))
36 #define LL_HIGHBIT (1LL << 63)
38 __private_extern__
int
39 _ldbl2array32dd(union IEEEl2bits u
, uint32_t *a
)
41 int bit
, shift
, highbit
, dexp
;
47 a
[0] = a
[1] = a
[2] = a
[3] = 0;
51 bzero(a64
, sizeof(a64
));
53 switch (__fpclassifyd(u
.d
[0])) {
56 * special case: if the head double only has the high (hidden)
57 * bit set, and the tail double is non-zero and is opposite
58 * in sign, then we increment extrabit to keep 106 bit
59 * precision in the results.
61 if(u
.bits
.manh
== 0 && u
.d
[1] != 0 && u
.bits
.sign
!= u
.bits
.sign2
)
63 a64
[1] = (1LL << (LDBL_MANT_DIG
- BITS64
- 1 + extrabit
));
64 a64
[1] |= ((uint64_t)u
.bits
.manh
>> (BITS64
- LDBL_MANL_SIZE
- extrabit
));
65 a64
[0] = ((uint64_t)u
.bits
.manh
<< (LDBL_MANL_SIZE
+ extrabit
));
68 a64
[1] |= ((uint64_t)u
.bits
.manh
>> (BITS64
- LDBL_MANL_SIZE
));
69 a64
[0] = ((uint64_t)u
.bits
.manh
<< LDBL_MANL_SIZE
);
70 /* the tail double will be zero, so we are done */
76 dexp
= (int)u
.bits
.exp
- (int)u
.bits
.exp2
;
78 * if the tail double is so small to not fit in LDBL_MANT_DIG bits,
81 if (dexp
>= LDBL_MANT_DIG
+ extrabit
) {
87 a64
[0] |= ((uint64_t)bit
) << (BITS64
- 1);
93 switch (__fpclassifyd(u
.d
[1])) {
95 bit
= LDBL_MANT_DIG
- dexp
- 1 + extrabit
;
99 bit
= LDBL_MANT_DIG
- (int)u
.bits
.exp
+ extrabit
;
103 /* should never get here */
106 shift
= LDBL_MANL_SIZE
- bit
- 1;
108 t64
|= (u
.bits
.manl
>> shift
);
110 t64
|= (u
.bits
.manl
<< (-shift
));
111 highbit
= ((a64
[0] & LL_HIGHBIT
) != 0);
112 if (u
.bits
.sign
== u
.bits
.sign2
) {
114 if (highbit
&& !(a64
[0] & LL_HIGHBIT
)) /* carry */
118 if (!highbit
&& (a64
[0] & LL_HIGHBIT
)) /* borrow */
123 a
[0] = (uint32_t)a64
[0];
124 a
[1] = (uint32_t)(a64
[0] >> 32);
125 a
[2] = (uint32_t)a64
[1];
126 a
[3] = (uint32_t)(a64
[1] >> 32);