public inbox for libc-hacker@sourceware.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Ulrich Drepper <drepper@redhat.com>
Cc: Glibc hackers <libc-hacker@sources.redhat.com>
Subject: [PATCH] Fix stdio-common/bug16.c
Date: Tue, 08 Aug 2006 11:54:00 -0000	[thread overview]
Message-ID: <20060808115352.GC4556@sunsite.mff.cuni.cz> (raw)

Hi!

This new test fails on ppc{,64}, s390{,x} (and I expect any other IEEE quad
or IBM extended long double arch).  The ISO C99 standard only requires that
before the dot (or P/p letter) is a non-zero hexadecimal digit (unless
subnormal), and as we do assume FLT_RADIX 2, that leaves us with 1, 2, 4 or
8.  On ppc*/s390* indeed snprintf prints 0x2P-1 rather than 0x1P+0.
Tested that this test still fails on x86_64 with broken glibc.

2006-08-08  Jakub Jelinek  <jakub@redhat.com>

	* stdio-common/bug16.c (tests): New array.
	(do_tests): Allow the first hexadecimal digit
	to be 1, 2, 4 or 8.  Do 3 additional tests.

--- libc/stdio-common/bug16.c.jj	2006-08-03 11:24:39.000000000 +0200
+++ libc/stdio-common/bug16.c	2006-08-08 10:38:11.000000000 +0200
@@ -1,19 +1,42 @@
 #include <stdio.h>
 #include <string.h>
 
+struct
+{
+  long double val;
+  const char str[4][7];
+} tests[] =
+{
+  { 0x0.FFFFp+0L, { "0X1P+0", "0X2P-1", "0X4P-2", "0X8P-3" } },
+  { 0x0.FFFFp+1L, { "0X1P+1", "0X2P+0", "0X4P-1", "0X8P-2" } },
+  { 0x0.FFFFp+2L, { "0X1P+2", "0X2P+1", "0X4P+0", "0X8P-1" } },
+  { 0x0.FFFFp+3L, { "0X1P+3", "0X2P+2", "0X4P+1", "0X8P+0" } }
+};
+
 static int
 do_test (void)
 {
   char buf[100];
-  snprintf (buf, sizeof (buf), "%.0LA", 0x0.FFFFp+0L);
+  int ret = 0;
+
+  for (size_t i = 0; i < sizeof (tests) / sizeof (tests[0]); ++i)
+    {  
+      snprintf (buf, sizeof (buf), "%.0LA", tests[i].val);
+
+      size_t j;
+      for (j = 0; j < 4; ++j)
+	if (strcmp (buf, tests[i].str[j]) == 0)
+	  break;
 
-  if (strcmp (buf, "0X1P+0") != 0)
-    {
-      printf ("got \"%s\", expected \"0X1P+0\"\n", buf);
-      return 1;
+      if (j == 4)
+	{
+	  printf ("%zd: got \"%s\", expected \"%s\" or equivalent\n",
+		  i, buf, tests[i].str[0]);
+	  ret = 1;
+	}
     }
 
-  return 0;
+  return ret;
 }
 
 #define TEST_FUNCTION do_test ()

	Jakub

             reply	other threads:[~2006-08-08 11:54 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-08-08 11:54 Jakub Jelinek [this message]
2006-08-08 15:45 ` Ulrich Drepper

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20060808115352.GC4556@sunsite.mff.cuni.cz \
    --to=jakub@redhat.com \
    --cc=drepper@redhat.com \
    --cc=libc-hacker@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).