]>
git.saurik.com Git - apple/libc.git/blob - gdtoa/FreeBSD/_ldbl_util.c
2 * Copyright (c) 2004 Apple Computer, 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>
34 #define DBL_BIAS (DBL_MAX_EXP - 1)
35 #define DBL_SUBEXP (-DBL_BIAS + 1)
36 #define LL_BITS (8 * sizeof(int64_t))
37 #define LL_HIGHBIT (1LL << 63)
39 __private_extern__
void
40 _ldbl2array32dd(union IEEEl2bits u
, uint32_t *a
)
42 int bit
, shift
, highbit
;
46 bzero(a64
, 2 * sizeof(*a64
));
48 switch (__fpclassifyd(u
.d
[0])) {
50 a64
[1] = (1LL << (LDBL_MANT_DIG
- BITS64
- 1));
53 a64
[1] |= ((uint64_t)u
.bits
.manh
>> (BITS64
- LDBL_MANL_SIZE
));
54 a64
[0] = ((uint64_t)u
.bits
.manh
<< LDBL_MANL_SIZE
);
60 switch (__fpclassifyd(u
.d
[1])) {
62 bit
= LDBL_MANT_DIG
- (int)u
.bits
.exp
+ (int)u
.bits
.exp2
- 1;
66 bit
= LDBL_MANT_DIG
- (int)u
.bits
.exp
;
72 shift
= LDBL_MANL_SIZE
- bit
- 1;
74 t64
|= (u
.bits
.manl
>> shift
);
76 t64
|= (u
.bits
.manl
<< (-shift
));
77 highbit
= ((a64
[0] & LL_HIGHBIT
) != 0);
78 if (u
.bits
.sign
== u
.bits
.sign2
) {
80 if (highbit
&& !(a64
[0] & LL_HIGHBIT
)) /* carry */
84 if (!highbit
&& (a64
[0] & LL_HIGHBIT
)) /* borrow */
89 a
[0] = (uint32_t)a64
[0];
90 a
[1] = (uint32_t)(a64
[0] >> 32);
91 a
[2] = (uint32_t)a64
[1];
92 a
[3] = (uint32_t)(a64
[1] >> 32);