[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[libdfp-patches] Fix bug in sysdeps/dpd/dpd-private.c: dpd_to_char[0x3f4] where "974" should be "774".
- To: libdfp-patches <libdfp-patches@xxxxxxxxxx>
- Subject: [libdfp-patches] Fix bug in sysdeps/dpd/dpd-private.c: dpd_to_char[0x3f4] where "974" should be "774".
- From: Ryan Arnold <rsa@xxxxxxxxxx>
- Date: Mon, 17 Jan 2011 20:40:25 -0600
I've checked the following patch in upstream:
r12583 | ryanarn | 2011-01-17 20:36:22 -0600 (Mon, 17 Jan 2011) | 20 lines
Checked in the following patch which fixed a bug in
sysdeps/dpd/dpd-private.c's dpd_to_char[0x3f4] element where what should be
"774" was actually "974". This caused some values that fell on a particular
boundary to be displayed with ....974.... instead of ....774.... Added a new
testcase to verify correct behavior.
2011-01-17 Ryan S. Arnold <rsa@xxxxxxxxxx>
* Makefile.in (libdfp_tests): Added test-log10d.
* tests/test-decode.c: Added decode of log10d128(0.0000000011DL) to
verify that it prints correctly in declets.
* tests/test-logd.c (main): Added pbuf[CHAR_MAX] so that tests work
properly.
* tests/test-log10d.c: New test-case which verifies that printf now
works properly for the result of log10d128(0.0000000011DL).
* sysdeps/dpd/dpd-private.c: Fixed dpd_to_char[0x3f4] from "974" to
"774" since the previous was a typo which was making values print
incorrectly.
===================================================================
--- Makefile.in (revision 12582)
+++ Makefile.in (working copy)
@@ -304,7 +304,7 @@
GLIBC_LIBS := $(glibc_builddir)/libc.so $(glibc_builddir)/math/libm.so $(glibc_builddir)/nptl/libpthread.so
endif
-libdfp_tests = test-printf test-param test-amort test-decode test-quantize test-isnan test-isinf test-isfinite test-fpclassify test-logd test-strtod test-numdigits test-get_digits test-round
+libdfp_tests = test-printf test-param test-amort test-decode test-quantize test-isnan test-isinf test-isfinite test-fpclassify test-logd test-log10d test-strtod test-numdigits test-get_digits test-round
# Explicitly link against the uninstalled GLIBC and the Libdfp.so.1 we just
# built.
Index: tests/test-log10d.c
===================================================================
--- tests/test-log10d.c (revision 0)
+++ tests/test-log10d.c (revision 12583)
@@ -0,0 +1,82 @@
+/* Test log10d[32|64|128].
+
+ Copyright (C) 2010 Free Software Foundation, Inc.
+
+ This file is part of the Decimal Floating Point C Library.
+
+ Author(s): Ryan S. Arnold <rsa@xxxxxxxxxx>
+
+ The Decimal Floating Point C Library is free software; you can
+ redistribute it and/or modify it under the terms of the GNU Lesser
+ General Public License version 2.1.
+
+ The Decimal Floating Point C Library is distributed in the hope that
+ it will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
+ the GNU Lesser General Public License version 2.1 for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License version 2.1 along with the Decimal Floating Point C Library;
+ if not, write to the Free Software Foundation, Inc., 59 Temple Place,
+ Suite 330, Boston, MA 02111-1307 USA.
+
+ Please see libdfp/COPYING.txt for more information. */
+
+#ifndef __STDC_WANT_DEC_FP__
+#define __STDC_WANT_DEC_FP__
+#endif
+
+#include <stdio.h>
+#include <math.h>
+#include <string.h>
+
+#define _WANT_VC 1 /* Pick up the _VC_P(x,y,fmt) macro. */
+
+#include "scaffold.c" /* Pick up the _VC_P(x,y,fmt) macro. */
+
+typedef struct{
+ int line;
+ _Decimal128 x; /* Value to test */
+ _Decimal128 e; /* Result should be this. */
+ const char *format; /* printf %DfDD */
+ char vorq; /* value compare or printf compare (quantize equivalent) */
+} d128_type;
+
+d128_type printf_d128s[] =
+{
+ /* This value revealed a typo in the dpd_to_char array in
+ * sysdeps/dpd/dpd-private.c which is used as a lookup table. What is now
+ * '774' was erroneously '974' and was resulting in incorrect display of the
+ * expected value.
+ *
+ * echo 'scale = 33; l(0.0000000011)/l(10)' | bc -l
+ * == -8.958607314841774959249800028756976 */
+ {__LINE__, 1.1E-9DL, -8.958607314841774959249800028756976DL, "%.34DDfDL",'v'},
+ {0,0,0,0,0 }
+};
+
+int main (void)
+{
+ d128_type *d128ptr;
+
+ for (d128ptr = printf_d128s; d128ptr->line; d128ptr += sizeof(_Decimal128 *))
+ {
+ _Decimal128 retval = log10d128(d128ptr->x);
+ fprintf(stdout,"%.34DDfDL = log10d128(%.34DDfDL) in: %s:%d\n", retval, d128ptr->x,__FILE__,__LINE__-1);
+ if(d128ptr->vorq == 'v')
+ _VC_P(__FILE__,d128ptr->line, d128ptr->e,retval,d128ptr->format);
+ if(d128ptr->e != retval)
+ {
+ static char rbuf[CHAR_MAX];
+ static char pbuf[CHAR_MAX];
+ fprintf(stderr,"decoded128(retval) [%s] != decoded128(expected) [%s]\n", decoded128(retval, &rbuf[0]), decoded128(d128ptr->e, &pbuf[0]));
+ }
+ }
+
+ _REPORT();
+
+ /* fail comes from scaffold.c */
+ return fail;
+}
+
+
Index: tests/test-decode.c
===================================================================
--- tests/test-decode.c (revision 12582)
+++ tests/test-decode.c (working copy)
@@ -84,6 +84,8 @@
#else
{__LINE__,1.00DL, "BID not supported."},
#endif
+ /* log10d128(0.0000000011DL) */
+ {__LINE__, -8.958607314841774959249800028756976DL, "-8,958,607,314,841,774,959,249,800,028,756,976E-33"},
{ 0,0,0 }
};
Index: tests/test-logd.c
===================================================================
--- tests/test-logd.c (revision 12582)
+++ tests/test-logd.c (working copy)
@@ -1,4 +1,4 @@
-/* Test islogd[32|64|128].
+/* Test logd[32|64|128].
Copyright (C) 2010 Free Software Foundation, Inc.
@@ -80,8 +80,6 @@
{0,0,0 }
};
-
-
int main (void)
{
d64_type *d64ptr;
@@ -96,7 +94,8 @@
if(d64ptr->e != retval)
{
static char rbuf[CHAR_MAX];
- fprintf(stderr,"decoded64(retval) [%s] != decoded64(expected) [%s]\n", decoded64(retval, &rbuf[0]), decoded64(d64ptr->e, &rbuf[0]));
+ static char pbuf[CHAR_MAX];
+ fprintf(stderr,"decoded64(retval) [%s] != decoded64(expected) [%s]\n", decoded64(retval, &rbuf[0]), decoded64(d64ptr->e, &pbuf[0]));
}
}
Index: sysdeps/dpd/dpd-private.c
===================================================================
--- sysdeps/dpd/dpd-private.c (revision 12582)
+++ sysdeps/dpd/dpd-private.c (working copy)
@@ -200,10 +200,12 @@
"758", "759", "794", "795", "956", "957", "798", "799", /* 3d8-3df */
"760", "761", "762", "763", "764", "765", "766", "767", /* 3e0-3e7 */
"768", "769", "786", "787", "966", "967", "988", "989", /* 3e8-3ef */
- "770", "771", "772", "773", "974", "775", "776", "777", /* 3f0-3f7 */
+ "770", "771", "772", "773", "774", "775", "776", "777", /* 3f0-3f7 */
"778", "779", "796", "797", "976", "977", "998", "999" /* 3f8-3ff */
};
+// "770", "771", "772", "773", "974", "775", "776", "777", /* 3f0-3f7 */
+
/* Table to convert 3 Densely Packed Decimal digits (10-bits) into
3 Binary coded Decimal digits (12-bits). */
const short int dpd_to_bcd[1024] = {
@@ -708,7 +710,8 @@
str[16] = '\0';
if (sign_p) *sign_p = d.ieee.negative;
}
-else if (bits == 128)
+//else if (bits == 128)
+else
{
union ieee754r_Decimal128 d;
d.td = *(_Decimal128*)args[0];
@@ -732,8 +735,6 @@
str[34] = '\0';
if (sign_p) *sign_p = d.ieee.negative;
}
-else
- return;
str[0] = '0' + c_f.lmd;
if (exp_p) *exp_p = exp;