---- _ldtoa.c.orig 2004-12-08 22:50:28.000000000 -0800
-+++ _ldtoa.c 2004-12-08 22:52:58.000000000 -0800
-@@ -61,14 +61,34 @@
+--- _ldtoa.c.orig 2004-06-03 15:17:18.000000000 -0700
++++ _ldtoa.c 2005-10-09 00:09:11.000000000 -0700
+@@ -46,7 +46,7 @@
+ __ldtoa(long double *ld, int mode, int ndigits, int *decpt, int *sign,
+ char **rve)
+ {
+- static FPI fpi = {
++ static FPI fpi0 = {
+ LDBL_MANT_DIG, /* nbits */
+ LDBL_MIN_EXP - LDBL_MANT_DIG, /* emin */
+ LDBL_MAX_EXP - LDBL_MANT_DIG, /* emax */
+@@ -61,28 +61,55 @@
char *ret;
union IEEEl2bits u;
uint32_t bits[(LDBL_MANT_DIG + 31) / 32];
++ FPI *fpi = &fpi0, fpi1;
++#ifdef Honor_FLT_ROUNDS
++ int rounding = Flt_Rounds;
++#endif
+#if defined(__ppc__) || defined(__ppc64__)
+ int type;
+#endif /* defined(__ppc__) || defined(__ppc64__) */
case FP_NORMAL:
+ case FP_SUPERNORMAL:
kind = STRTOG_Normal;
++/* For ppc/ppc64 and head-tail long double, the implicit bit is already there */
++#if !defined(__ppc__) && !defined(__ppc64__)
#ifdef LDBL_IMPLICIT_NBIT
bits[LDBL_MANT_DIG / 32] |= 1 << ((LDBL_MANT_DIG - 1) % 32);
-@@ -77,12 +97,14 @@
+ #endif /* LDBL_IMPLICIT_NBIT */
++#endif /* !defined(__ppc__) && !defined(__ppc64__) */
+ break;
case FP_ZERO:
kind = STRTOG_Zero;
break;
+#if !defined(__ppc__) && !defined(__ppc64__)
case FP_SUBNORMAL:
kind = STRTOG_Denormal;
- #ifdef LDBL_IMPLICIT_NBIT
+-#ifdef LDBL_IMPLICIT_NBIT
be++;
- #endif
+-#endif
break;
+#endif /* !defined(__ppc__) && !defined(__ppc64__) */
case FP_INFINITE:
kind = STRTOG_Infinite;
break;
-@@ -96,5 +118,9 @@
- ret = gdtoa(&fpi, be, (ULong *)bits, &kind, mode, ndigits, decpt, rve);
+@@ -93,8 +120,19 @@
+ abort();
+ }
+
+- ret = gdtoa(&fpi, be, (ULong *)bits, &kind, mode, ndigits, decpt, rve);
++#ifdef Honor_FLT_ROUNDS
++ if (rounding != fpi0.rounding) {
++ fpi1 = fpi0; /* for thread safety */
++ fpi1.rounding = rounding;
++ fpi = &fpi1;
++ }
++#endif /* Honor_FLT_ROUNDS */
++ ret = gdtoa(fpi, be, (ULong *)bits, &kind, mode, ndigits, decpt, rve);
if (*decpt == -32768)
*decpt = INT_MAX;
+#if defined(__ppc__) || defined(__ppc64__)