Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | --- _hdtoa.c.orig 2008-09-07 11:38:10.000000000 -0700 +++ _hdtoa.c 2008-09-07 12:49:47.000000000 -0700 @@ -55,7 +55,7 @@ roundup(char *s0, int ndigits) *s = 1; return (1); } - ++*s; + *s = 0; } ++*s; return (0); @@ -126,12 +126,12 @@ __hdtoa(double d, const char *xdigs, int static const int sigfigs = (DBL_MANT_DIG + 3) / 4; union IEEEd2bits u; char *s, *s0; - int bufsize; + int bufsize, f; u.d = d; *sign = u.bits.sign; - switch (fpclassify(d)) { + switch (f = fpclassify(d)) { case FP_NORMAL: *decpt = u.bits.exp - DBL_ADJ; break; @@ -149,7 +149,7 @@ __hdtoa(double d, const char *xdigs, int *decpt = INT_MAX; return (nrv_alloc(NANSTR, rve, sizeof(NANSTR) - 1)); default: - abort(); + LIBC_ABORT("fpclassify returned %d", f); } /* FP_NORMAL or FP_SUBNORMAL */ @@ -210,6 +210,7 @@ __hdtoa(double d, const char *xdigs, int return (s0); } +#ifndef LDBL_COMPAT #if (LDBL_MANT_DIG > DBL_MANT_DIG) /* @@ -222,13 +223,18 @@ __hldtoa(long double e, const char *xdig static const int sigfigs = (LDBL_MANT_DIG + 3) / 4; union IEEEl2bits u; char *s, *s0; - int bufsize; + int bufsize, f; +#ifdef LDBL_HEAD_TAIL_PAIR + uint32_t bits[4]; + int i, pos; +#endif /* LDBL_HEAD_TAIL_PAIR */ u.e = e; *sign = u.bits.sign; - switch (fpclassify(e)) { + switch (f = fpclassify(e)) { case FP_NORMAL: + case FP_SUPERNORMAL: *decpt = u.bits.exp - LDBL_ADJ; break; case FP_ZERO: @@ -245,7 +251,7 @@ __hldtoa(long double e, const char *xdig *decpt = INT_MAX; return (nrv_alloc(NANSTR, rve, sizeof(NANSTR) - 1)); default: - abort(); + LIBC_ABORT("fpclassify returned %d", f); } /* FP_NORMAL or FP_SUBNORMAL */ @@ -270,6 +276,19 @@ __hldtoa(long double e, const char *xdig */ for (s = s0 + bufsize - 1; s > s0 + sigfigs - 1; s--) *s = 0; +#ifdef LDBL_HEAD_TAIL_PAIR + *decpt -= _ldbl2array32dd(u, bits); + i = 0; + pos = 8; + for (; s > s0; s--) { + *s = bits[i] & 0xf; + bits[i] >>= 4; + if (--pos <= 0) { + i++; + pos = 8; + } + } +#else /* LDBL_HEAD_TAIL_PAIR */ for (; s > s0 + sigfigs - (LDBL_MANL_SIZE / 4) - 1 && s > s0; s--) { *s = u.bits.manl & 0xf; u.bits.manl >>= 4; @@ -278,6 +297,7 @@ __hldtoa(long double e, const char *xdig *s = u.bits.manh & 0xf; u.bits.manh >>= 4; } +#endif /* LDBL_HEAD_TAIL_PAIR */ /* * At this point, we have snarfed all the bits in the @@ -285,7 +305,11 @@ __hldtoa(long double e, const char *xdig * (partial) nibble, which is dealt with by the next * statement. We also tack on the implicit normalization bit. */ +#ifdef LDBL_HEAD_TAIL_PAIR + *s = bits[i]; +#else /* LDBL_HEAD_TAIL_PAIR */ *s = u.bits.manh | (1U << ((LDBL_MANT_DIG - 1) % 4)); +#endif /* LDBL_HEAD_TAIL_PAIR */ /* If ndigits < 0, we are expected to auto-size the precision. */ if (ndigits < 0) { @@ -317,3 +341,4 @@ __hldtoa(long double e, const char *xdig } #endif /* (LDBL_MANT_DIG == DBL_MANT_DIG) */ +#endif /* !LDBL_COMPAT */ |