mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Dan Gohman <sunfish@mozilla.com>
To: musl@lists.openwall.com
Subject: [PATCH] Use fabsl instead of fabs on long double operand in floatscan.c
Date: Fri, 18 Oct 2019 07:02:11 -0700	[thread overview]
Message-ID: <CACcSVPFcd0G7MsZnEEgDhyYT5gZS9-8kfkKGVHR6RSqSE3_LFQ@mail.gmail.com> (raw)


[-- Attachment #1.1: Type: text/plain, Size: 494 bytes --]

This fixes a compiler warning with clang:

floatscan.c:304:13: warning: absolute value function 'fabs' given an
argument of type 'long double' but has parameter of type 'double' which may
cause truncation of value [-Wabsolute-value].

This does change the behavior of the expression because the value is no
longer rounded to double, however from my reading of the code, the rounding
doesn't seem intended. However, if it is, I suggest introducing an explicit
cast, to document the intent.

Dan

[-- Attachment #1.2: Type: text/html, Size: 617 bytes --]

[-- Attachment #2: 0001-Use-fabsl-instead-of-fabs-on-long-double-in-floatsca.patch --]
[-- Type: text/x-patch, Size: 1059 bytes --]

From 1fecc521dc43b25366cd4a3062964ff3abc7506e Mon Sep 17 00:00:00 2001
From: Dan Gohman <sunfish@mozilla.com>
Date: Fri, 18 Oct 2019 06:22:49 -0700
Subject: [PATCH] Use `fabsl` instead of `fabs` on long double in floatscan.c

This fixes a compiler warning:

floatscan.c:304:13: warning: absolute value function 'fabs' given an argument
of type 'long double' but has parameter of type 'double' which may cause
truncation of value [-Wabsolute-value]
---
 src/internal/floatscan.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/internal/floatscan.c b/src/internal/floatscan.c
index 278bf250..99a1ec29 100644
--- a/src/internal/floatscan.c
+++ b/src/internal/floatscan.c
@@ -301,7 +301,7 @@ static long double decfloat(FILE *f, int c, int bits, int emin, int sign, int po
 	y -= bias;
 
 	if ((e2+LDBL_MANT_DIG & INT_MAX) > emax-5) {
-		if (fabs(y) >= CONCAT(0x1p, LDBL_MANT_DIG)) {
+		if (fabsl(y) >= CONCAT(CONCAT(0x1p, LDBL_MANT_DIG), l)) {
 			if (denormal && bits==LDBL_MANT_DIG+e2-emin)
 				denormal = 0;
 			y *= 0.5;
-- 
2.17.1


             reply	other threads:[~2019-10-18 14:02 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-18 14:02 Dan Gohman [this message]
2019-10-18 14:23 ` Rich Felker
2019-10-18 14:49 ` Szabolcs Nagy
2019-10-19  1:19   ` Rich Felker

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=CACcSVPFcd0G7MsZnEEgDhyYT5gZS9-8kfkKGVHR6RSqSE3_LFQ@mail.gmail.com \
    --to=sunfish@mozilla.com \
    --cc=musl@lists.openwall.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.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

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 NNTP newsgroup(s).