From patchwork Tue Jun 2 17:15:41 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wilco X-Patchwork-Id: 479606 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id C9B601412E3 for ; Wed, 3 Jun 2015 03:16:08 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=sourceware.org header.i=@sourceware.org header.b=gnp4TjhX; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:mime-version :content-type:content-transfer-encoding; q=dns; s=default; b=pQi kdAtQxyhlVitp1/lYqjVrVJAU4ovcy7Vy74UQ5uszOU1tWGHtBElnw0bkPZXYGSv aBONwUScUI59Srfqdy/c45EPGWF1vheoi8xTiQdgiVqpDcBwhyDdle8WuCc5hG0X OdDczjAVJVpa4TVMyfBB/IhHowFV4nWI1tgoHtbs= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:mime-version :content-type:content-transfer-encoding; s=default; bh=NGMpuG0LY JzDOVKMZON/nxcCGaw=; b=gnp4TjhX0uadwVu/GiWfucC4J75GlI23Y3ulslb25 a6CfW4JnGTJMipeXbbyINUzDHLULhUyBljYhjq9JybOfle8lYLhgZWnCAtOlo5uB 83dLx4NL5j26vNJvL+3lzYD7uJgNPQyXKaiHnE9zg6CJ3ydzg457oV/xxLXc7mJl Ic= Received: (qmail 83439 invoked by alias); 2 Jun 2015 17:16:01 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 83430 invoked by uid 89); 2 Jun 2015 17:16:01 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.5 required=5.0 tests=AWL, BAYES_50, SPF_PASS autolearn=ham version=3.3.2 X-HELO: eu-smtp-delivery-143.mimecast.com From: "Wilco Dijkstra" To: "GNU C Library" Subject: [PATCH] Remove __isinf uses that rely on signed return value Date: Tue, 2 Jun 2015 18:15:41 +0100 Message-ID: <001301d09d57$c0bfdf60$423f9e20$@com> MIME-Version: 1.0 X-MC-Unique: EVGTfAS4Rkm_TBeMMqcJqQ-1 The printf code contains a few uses of __isinf where the sign is used - replace these with separate isinf and signbit. Also change __isnan into isnan. OK for commit? Wilco 2015-06-02 Wilco Dijkstra * stdio-common/printf_fp.c (___printf_fp): Use signbit to get the sign. Use isinf/isnan macros. * stdio-common/printf_fphex.c (__printf_fphex): Likewise. * stdio-common/printf_size.c (__printf_size): Likewise. --- stdio-common/printf_fp.c | 17 +++++++---------- stdio-common/printf_fphex.c | 14 +++++--------- stdio-common/printf_size.c | 23 +++++++++++------------ 3 files changed, 23 insertions(+), 31 deletions(-) diff --git a/stdio-common/printf_fp.c b/stdio-common/printf_fp.c index 575842b..11f3145 100644 --- a/stdio-common/printf_fp.c +++ b/stdio-common/printf_fp.c @@ -332,8 +332,7 @@ ___printf_fp (FILE *fp, fpnum.ldbl = *(const long double *) args[0]; /* Check for special values: not a number or infinity. */ - int res; - if (__isnanl (fpnum.ldbl)) + if (isnan (fpnum.ldbl)) { is_neg = signbit (fpnum.ldbl); if (isupper (info->spec)) @@ -347,9 +346,9 @@ ___printf_fp (FILE *fp, wspecial = L"nan"; } } - else if ((res = __isinfl (fpnum.ldbl))) + else if (isinf (fpnum.ldbl)) { - is_neg = res < 0; + is_neg = signbit (fpnum.ldbl); if (isupper (info->spec)) { special = "INF"; @@ -377,11 +376,9 @@ ___printf_fp (FILE *fp, fpnum.dbl = *(const double *) args[0]; /* Check for special values: not a number or infinity. */ - int res; - if (__isnan (fpnum.dbl)) + if (isnan (fpnum.dbl)) { - union ieee754_double u = { .d = fpnum.dbl }; - is_neg = u.ieee.negative != 0; + is_neg = signbit (fpnum.dbl); if (isupper (info->spec)) { special = "NAN"; @@ -393,9 +390,9 @@ ___printf_fp (FILE *fp, wspecial = L"nan"; } } - else if ((res = __isinf (fpnum.dbl))) + else if (isinf (fpnum.dbl)) { - is_neg = res < 0; + is_neg = signbit (fpnum.dbl); if (isupper (info->spec)) { special = "INF"; diff --git a/stdio-common/printf_fphex.c b/stdio-common/printf_fphex.c index ba0639f..0627bea 100644 --- a/stdio-common/printf_fphex.c +++ b/stdio-common/printf_fphex.c @@ -165,7 +165,7 @@ __printf_fphex (FILE *fp, fpnum.ldbl = *(const long double *) args[0]; /* Check for special values: not a number or infinity. */ - if (__isnanl (fpnum.ldbl)) + if (isnan (fpnum.ldbl)) { if (isupper (info->spec)) { @@ -180,7 +180,7 @@ __printf_fphex (FILE *fp, } else { - if (__isinfl (fpnum.ldbl)) + if (isinf (fpnum.ldbl)) { if (isupper (info->spec)) { @@ -202,9 +202,8 @@ __printf_fphex (FILE *fp, fpnum.dbl.d = *(const double *) args[0]; /* Check for special values: not a number or infinity. */ - if (__isnan (fpnum.dbl.d)) + if (isnan (fpnum.dbl.d)) { - negative = fpnum.dbl.ieee.negative != 0; if (isupper (info->spec)) { special = "NAN"; @@ -218,8 +217,7 @@ __printf_fphex (FILE *fp, } else { - int res = __isinf (fpnum.dbl.d); - if (res) + if (isinf (fpnum.dbl.d)) { if (isupper (info->spec)) { @@ -231,11 +229,9 @@ __printf_fphex (FILE *fp, special = "inf"; wspecial = L"inf"; } - negative = res < 0; } - else - negative = signbit (fpnum.dbl.d); } + negative = signbit (fpnum.dbl.d); } if (special) diff --git a/stdio-common/printf_size.c b/stdio-common/printf_size.c index 6ee753f..216f170 100644 --- a/stdio-common/printf_size.c +++ b/stdio-common/printf_size.c @@ -108,7 +108,7 @@ __printf_size (FILE *fp, const struct printf_info *info, fpnum; const void *ptr = &fpnum; - int fpnum_sign = 0; + int is_neg = 0; /* "NaN" or "Inf" for the special cases. */ const char *special = NULL; @@ -117,7 +117,6 @@ __printf_size (FILE *fp, const struct printf_info *info, struct printf_info fp_info; int done = 0; int wide = info->wide; - int res; /* Fetch the argument value. */ #ifndef __NO_LONG_DOUBLE_MATH @@ -126,15 +125,15 @@ __printf_size (FILE *fp, const struct printf_info *info, fpnum.ldbl = *(const long double *) args[0]; /* Check for special values: not a number or infinity. */ - if (__isnanl (fpnum.ldbl)) + if (isnan (fpnum.ldbl)) { special = "nan"; wspecial = L"nan"; - // fpnum_sign = 0; Already zero + // is_neg = 0; Already zero } - else if ((res = __isinfl (fpnum.ldbl))) + else if (isinf (fpnum.ldbl)) { - fpnum_sign = res; + is_neg = signbit (fpnum.ldbl); special = "inf"; wspecial = L"inf"; } @@ -151,15 +150,15 @@ __printf_size (FILE *fp, const struct printf_info *info, fpnum.dbl.d = *(const double *) args[0]; /* Check for special values: not a number or infinity. */ - if (__isnan (fpnum.dbl.d)) + if (isnan (fpnum.dbl.d)) { special = "nan"; wspecial = L"nan"; - // fpnum_sign = 0; Already zero + // is_neg = 0; Already zero } - else if ((res = __isinf (fpnum.dbl.d))) + else if (isinf (fpnum.dbl.d)) { - fpnum_sign = res; + is_neg = signbit (fpnum.dbl.d); special = "inf"; wspecial = L"inf"; } @@ -175,14 +174,14 @@ __printf_size (FILE *fp, const struct printf_info *info, { int width = info->prec > info->width ? info->prec : info->width; - if (fpnum_sign < 0 || info->showsign || info->space) + if (is_neg || info->showsign || info->space) --width; width -= 3; if (!info->left && width > 0) PADN (' ', width); - if (fpnum_sign < 0) + if (is_neg) outchar ('-'); else if (info->showsign) outchar ('+');