From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2155) id 1398A3947413; Tue, 10 Mar 2020 14:46:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1398A3947413 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1583851606; bh=QnPPFp8Fyyr/xhOjM+yI2ZRI8g9FTHF1geXUUIEI4/c=; h=From:To:Subject:Date:From; b=rbJJ/3p2a71YJqyXjBGxmmx9HhqHBSvkg8H2SlMBQpqppvwKm7A4pJEsJPKpM8NgN 8qjMII1rcJYiXoiFIW2d3wbAHBD6KAYXprRFo9+dfnWfiSuch7TIOM7B2L8+9/2vDl W3fpL3HstHS4GcrhowiNyq/iVJEAbPl+0vjNw9s0= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Corinna Vinschen To: newlib-cvs@sourceware.org Subject: [newlib-cygwin] Fix error in fdim/f for infinities X-Act-Checkin: newlib-cygwin X-Git-Author: Fabian Schriever X-Git-Refname: refs/heads/master X-Git-Oldrev: a8a40ee5750cb8a4280379a38c1ed490262481c4 X-Git-Newrev: 18b4e0e5187f7e2076661e53747977f21dabedff Message-Id: <20200310144646.1398A3947413@sourceware.org> Date: Tue, 10 Mar 2020 14:46:46 +0000 (GMT) X-BeenThere: newlib-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Newlib-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 10 Mar 2020 14:46:46 -0000 https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=18b4e0e5187f7e2076661e53747977f21dabedff commit 18b4e0e5187f7e2076661e53747977f21dabedff Author: Fabian Schriever Date: Tue Mar 10 11:24:12 2020 +0100 Fix error in fdim/f for infinities The comparison c == FP_INFINITE causes the function to return +inf as it expects x = +inf to always be larger than y. This shortcut causes several issues as it also returns +inf for the following cases: - fdim(+inf, +inf), expected (as per C99): +0.0 - fdim(-inf, any non NaN), expected: +0.0 I don't see a reason to keep the comparison as all the infinity cases return the correct result using just the ternary operation. Diff: --- newlib/libm/common/s_fdim.c | 5 +---- newlib/libm/common/sf_fdim.c | 5 +---- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/newlib/libm/common/s_fdim.c b/newlib/libm/common/s_fdim.c index 73a027953..61a4908f3 100644 --- a/newlib/libm/common/s_fdim.c +++ b/newlib/libm/common/s_fdim.c @@ -49,11 +49,8 @@ ANSI C, POSIX. double y; #endif { - int c = __fpclassifyd(x); - if (c == FP_NAN) return(x); + if (__fpclassifyd(x) == FP_NAN) return(x); if (__fpclassifyd(y) == FP_NAN) return(y); - if (c == FP_INFINITE) - return HUGE_VAL; return x > y ? x - y : 0.0; } diff --git a/newlib/libm/common/sf_fdim.c b/newlib/libm/common/sf_fdim.c index fe349098b..8fee57002 100644 --- a/newlib/libm/common/sf_fdim.c +++ b/newlib/libm/common/sf_fdim.c @@ -14,11 +14,8 @@ float y; #endif { - int c = __fpclassifyf(x); - if (c == FP_NAN) return(x); + if (__fpclassifyf(x) == FP_NAN) return(x); if (__fpclassifyf(y) == FP_NAN) return(y); - if (c == FP_INFINITE) - return HUGE_VALF; return x > y ? x - y : 0.0; }