]> git.saurik.com Git - apple/libc.git/blame - gdtoa/FreeBSD/_hdtoa.c.patch
Libc-391.2.5.tar.gz
[apple/libc.git] / gdtoa / FreeBSD / _hdtoa.c.patch
CommitLineData
3d9156a7
A
1--- _hdtoa.c.orig 2004-06-03 15:22:08.000000000 -0700
2+++ _hdtoa.c 2004-08-28 17:10:21.000000000 -0700
3@@ -32,6 +32,9 @@
4 #include <limits.h>
5 #include <math.h>
6 #include <stdlib.h>
7+#ifdef LDBL_HEAD_TAIL_PAIR
8+#include <alloca.h>
9+#endif /* LDBL_HEAD_TAIL_PAIR */
10 #include "fpmath.h"
11 #include "gdtoaimp.h"
12
13@@ -301,16 +304,31 @@
14 int pos;
15 int shift; /* for subnormals, # of shifts required to normalize */
16 int sigfigs; /* number of significant hex figures in result */
17+#ifdef LDBL_HEAD_TAIL_PAIR
18+ uint32_t bits[4];
19+ int i;
20+#endif /* LDBL_HEAD_TAIL_PAIR */
21
22 u.e = e;
23 *sign = u.bits.sign;
24
25+#ifdef LDBL_HEAD_TAIL_PAIR
26+ switch (__fpclassifyd(u.d[0])) {
27+#else /* LDBL_HEAD_TAIL_PAIR */
28 switch (fpclassify(e)) {
29+#endif /* LDBL_HEAD_TAIL_PAIR */
30 case FP_NORMAL:
31+#ifdef LDBL_HEAD_TAIL_PAIR
32 sigfigs = (LDBL_MANT_DIG + 3) / 4;
33 impnbit = 1 << ((LDBL_MANT_DIG - 1) % 4);
34 *decpt = u.bits.exp - LDBL_BIAS + 1 -
35 ((LDBL_MANT_DIG - 1) % 4);
36+#else /* LDBL_HEAD_TAIL_PAIR */
37+ sigfigs = (LDBL_MANT_DIG + 3) / 4;
38+ impnbit = 1 << ((LDBL_MANT_DIG - 1) % 4);
39+ *decpt = u.bits.exp - LDBL_BIAS + 1 -
40+ ((LDBL_MANT_DIG - 1) % 4);
41+#endif /* LDBL_HEAD_TAIL_PAIR */
42 break;
43 case FP_ZERO:
44 *decpt = 1;
45@@ -328,13 +346,26 @@
46 /* Don't trust the normalization bit to be off. */
47 u.bits.manh &= ~(~0ULL << (LDBL_MANH_SIZE - 1));
48 #endif
49+#ifndef LDBL_HEAD_TAIL_PAIR
50 if (u.bits.manh != 0) {
51+#endif /* LDBL_HEAD_TAIL_PAIR */
52 #if LDBL_MANH_SIZE > 32
53 pos = log2_64(u.bits.manh);
54 #else
55 pos = log2_32(u.bits.manh);
56 #endif
57 shift = LDBL_MANH_SIZE - LDBL_NBIT_ADJ - pos;
58+#ifdef LDBL_HEAD_TAIL_PAIR
59+ sigfigs = (3 + LDBL_MANT_DIG - LDBL_NBIT_ADJ - shift) / 4;
60+ // we use DBL_MIN_EXP below because the head double is
61+ // subnormal (and the tail double is zero)
62+ *decpt = DBL_MIN_EXP + LDBL_NBIT_ADJ;
63+ pos = (LDBL_MANT_DIG + 3) % 4;
64+ if (pos < shift)
65+ *decpt -= pos + ((shift - pos + 3) & ~(4 - 1));
66+ else
67+ *decpt -= shift;
68+#else /* LDBL_HEAD_TAIL_PAIR */
69 } else {
70 #if LDBL_MANL_SIZE > 32
71 pos = log2_64(u.bits.manl);
72@@ -345,8 +376,9 @@
73 LDBL_NBIT_ADJ - pos;
74 }
75 sigfigs = (3 + LDBL_MANT_DIG - LDBL_NBIT_ADJ - shift) / 4;
76- *decpt = LDBL_MIN_EXP + LDBL_NBIT_ADJ -
77+ *decpt = DBL_MIN_EXP + LDBL_NBIT_ADJ -
78 ((shift + 3) & ~(4 - 1));
79+#endif /* LDBL_HEAD_TAIL_PAIR */
80 impnbit = 0;
81 break;
82 case FP_INFINITE:
83@@ -381,6 +413,19 @@
84 */
85 for (s = s0 + bufsize - 1; s > s0 + sigfigs - 1; s--)
86 *s = 0;
87+#ifdef LDBL_HEAD_TAIL_PAIR
88+ _ldbl2array32dd(u, bits);
89+ i = 0;
90+ pos = 8;
91+ for (; s > s0; s--) {
92+ *s = bits[i] & 0xf;
93+ bits[i] >>= 4;
94+ if (--pos <= 0) {
95+ i++;
96+ pos = 8;
97+ }
98+ }
99+#else /* LDBL_HEAD_TAIL_PAIR */
100 for (; s > s0 + sigfigs - (LDBL_MANL_SIZE / 4) - 1 && s > s0; s--) {
101 *s = u.bits.manl & 0xf;
102 u.bits.manl >>= 4;
103@@ -389,6 +434,7 @@
104 *s = u.bits.manh & 0xf;
105 u.bits.manh >>= 4;
106 }
107+#endif /* LDBL_HEAD_TAIL_PAIR */
108
109 /*
110 * At this point, we have snarfed all the bits in the
111@@ -398,7 +444,11 @@
112 * in manl instead for small subnormals. We also tack on the
113 * implicit normalization bit if appropriate.
114 */
115+#ifdef LDBL_HEAD_TAIL_PAIR
116+ *s = bits[i] | impnbit;
117+#else /* LDBL_HEAD_TAIL_PAIR */
118 *s = u.bits.manh | u.bits.manl | impnbit;
119+#endif /* LDBL_HEAD_TAIL_PAIR */
120
121 /* If ndigits < 0, we are expected to auto-size the precision. */
122 if (ndigits < 0) {