]> git.saurik.com Git - apple/libc.git/blob - gdtoa/FreeBSD/_ldtoa.c.patch
Libc-391.4.1.tar.gz
[apple/libc.git] / gdtoa / FreeBSD / _ldtoa.c.patch
1 --- _ldtoa.c.orig 2004-06-03 15:17:18.000000000 -0700
2 +++ _ldtoa.c 2005-10-08 22:43:25.000000000 -0700
3 @@ -61,14 +61,34 @@
4 char *ret;
5 union IEEEl2bits u;
6 uint32_t bits[(LDBL_MANT_DIG + 31) / 32];
7 +#if defined(__ppc__) || defined(__ppc64__)
8 + int type;
9 +#endif /* defined(__ppc__) || defined(__ppc64__) */
10
11 u.e = *ld;
12 +#if defined(__ppc__) || defined(__ppc64__)
13 + /*
14 + * Subnormal head-tail doubles don't seem to be converted correctly
15 + * by gdtoa. So we multiply by 10^32 to make them normal then
16 + * subtract 32 from the exponent later.
17 + */
18 + if ((type = __fpclassify(u.e)) == FP_NORMAL && __fpclassifyd(u.d[1]) == FP_SUBNORMAL)
19 + type = FP_SUBNORMAL;
20 + if (type == FP_SUBNORMAL)
21 + u.e *= 1.0e32L;
22 +#endif /* defined(__ppc__) || defined(__ppc64__) */
23 *sign = u.bits.sign;
24 be = u.bits.exp - (LDBL_MAX_EXP - 1) - (LDBL_MANT_DIG - 1);
25 LDBL_TO_ARRAY32(u, bits);
26
27 +#if defined(__ppc__) || defined(__ppc64__)
28 + switch (type) {
29 + case FP_SUBNORMAL:
30 +#else /* !defined(__ppc__) && !defined(__ppc64__) */
31 switch (fpclassify(u.e)) {
32 +#endif /* defined(__ppc__) || defined(__ppc64__) */
33 case FP_NORMAL:
34 + case FP_SUPERNORMAL:
35 kind = STRTOG_Normal;
36 #ifdef LDBL_IMPLICIT_NBIT
37 bits[LDBL_MANT_DIG / 32] |= 1 << ((LDBL_MANT_DIG - 1) % 32);
38 @@ -77,12 +97,12 @@
39 case FP_ZERO:
40 kind = STRTOG_Zero;
41 break;
42 +#if !defined(__ppc__) && !defined(__ppc64__)
43 case FP_SUBNORMAL:
44 kind = STRTOG_Denormal;
45 -#ifdef LDBL_IMPLICIT_NBIT
46 be++;
47 -#endif
48 break;
49 +#endif /* !defined(__ppc__) && !defined(__ppc64__) */
50 case FP_INFINITE:
51 kind = STRTOG_Infinite;
52 break;
53 @@ -96,5 +116,9 @@
54 ret = gdtoa(&fpi, be, (ULong *)bits, &kind, mode, ndigits, decpt, rve);
55 if (*decpt == -32768)
56 *decpt = INT_MAX;
57 +#if defined(__ppc__) || defined(__ppc64__)
58 + else if (type == FP_SUBNORMAL)
59 + *decpt -= 32;
60 +#endif /* defined(__ppc__) || defined(__ppc64__) */
61 return ret;
62 }