From patchwork Wed Jan 27 04:45:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Hommey X-Patchwork-Id: 41824 X-Patchwork-Delegate: azanella@linux.vnet.ibm.com Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A3106384388B; Wed, 27 Jan 2021 04:45:25 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from vuizook.err.no (vuizook.err.no [IPv6:2a02:20c8:2640::2]) by sourceware.org (Postfix) with ESMTPS id 74A4D386102D for ; Wed, 27 Jan 2021 04:45:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 74A4D386102D Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=glandium.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=glandium@glandium.org Received: from [2400:4160:1877:2b00:485c:a843:4129:ffd4] (helo=glandium.org) by vuizook.err.no with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l4chg-0003p5-SL; Wed, 27 Jan 2021 04:45:19 +0000 Received: from glandium by goemon.lan with local (Exim 4.92) (envelope-from ) id 1l4chb-0001mG-Cr; Wed, 27 Jan 2021 13:45:11 +0900 From: Mike Hommey To: libc-alpha@sourceware.org Subject: [PATCH] stdio-common: Add a few double formatting tests [BZ #27245] Date: Wed, 27 Jan 2021 13:45:05 +0900 Message-Id: <20210127044505.6783-1-mh@glandium.org> X-Mailer: git-send-email 2.30.0 MIME-Version: 1.0 X-Spam-Status: No, score=-13.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mike Hommey Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" This adds tests for corner cases that I've found while implementing a printf based on https://github.com/google/double-conversion/ but weren't covered by the printf formatting tests in glibc (which I was using as a source of test cases). Copyright-paperwork-exempt: Yes Reviewed-by: Adhemerval Zanella --- stdio-common/tfformat.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/stdio-common/tfformat.c b/stdio-common/tfformat.c index 5cb366dd48..4eb47f0c2b 100644 --- a/stdio-common/tfformat.c +++ b/stdio-common/tfformat.c @@ -1,3 +1,4 @@ +#include #include /* Tests taken from Cygnus C library. */ @@ -4009,6 +4010,10 @@ sprint_double_type sprint_doubles[] = {__LINE__, 11.25, "11.2", "%.1f"}, {__LINE__, 1.75, "1.8", "%.1f"}, {__LINE__, 11.75, "11.8", "%.1f"}, + {__LINE__, -1.25, "-1.2", "%.1f"}, + {__LINE__, -11.25, "-11.2", "%.1f"}, + {__LINE__, -1.75, "-1.8", "%.1f"}, + {__LINE__, -11.75, "-11.8", "%.1f"}, {__LINE__, 16, "0x1.0p+4", "%.1a"}, {__LINE__, 16, "0x1.00000000000000000000p+4", "%.20a"}, {__LINE__, 4444.88888888, "4445", "%2.F"}, @@ -4039,6 +4044,29 @@ sprint_double_type sprint_doubles[] = {__LINE__, 912.98, "913", "%.4g"}, {__LINE__, 50.999999, "51", "%.5g"}, + {__LINE__, 0.0, "0000.00000", "%010.5f"}, + {__LINE__, 0.0, " 000.00000", "% 010.5f"}, + {__LINE__, -0.0, "-000.00000", "% 010.5f"}, + + {__LINE__, NAN, "nan", "%f"}, + {__LINE__, NAN, "+nan", "%+f"}, + {__LINE__, NAN, " nan", "%010.2f"}, + {__LINE__, NAN, " +nan", "%+010.2f"}, + {__LINE__, -NAN, "-nan", "%f"}, + {__LINE__, -NAN, "-nan", "%+f"}, + {__LINE__, -NAN, " -nan", "%010.2f"}, + {__LINE__, -NAN, " -nan", "%+010.2f"}, + {__LINE__, NAN, "NAN", "%F"}, + {__LINE__, INFINITY, "inf", "%f"}, + {__LINE__, INFINITY, "+inf", "%+f"}, + {__LINE__, INFINITY, " inf", "%010.2f"}, + {__LINE__, INFINITY, " +inf", "%+010.2f"}, + {__LINE__, -INFINITY, "-inf", "%f"}, + {__LINE__, -INFINITY, "-inf", "%+f"}, + {__LINE__, -INFINITY, " -inf", "%010.2f"}, + {__LINE__, -INFINITY, " -inf", "%+010.2f"}, + {__LINE__, INFINITY, "INF", "%F"}, + {0 } }; @@ -4090,7 +4118,7 @@ int main(int argc, char *argv[]) sprintf (buffer, "%.999g", dptr->value); sscanf (buffer, "%lg", &d); - if (dptr->value != d) + if (dptr->value != d && !isnan(d)) { errcount++; printf ("Error in line %d. String is \"%s\", value is %g.\n",